How to make this code work ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How to make this code work ?

This isn't working How to change "+" into just + Here, https://code.sololearn.com/W17lrO6J9bOU/?ref=app

7th Dec 2018, 4:58 AM
Googel
Googel - avatar
6 Answers
+ 8
console.log(eval('1+ 1')); alert(eval('1 + 1'));
7th Dec 2018, 5:06 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 6
If you want only to print string then you can use this console.log(eval(new String('2 + 2')));
7th Dec 2018, 5:28 AM
GAWEN STEASY
GAWEN STEASY - avatar
+ 3
I wanted to do that differently
7th Dec 2018, 5:06 AM
Googel
Googel - avatar
+ 3
I know that. I want to do that separately. How to change "+" into just +
7th Dec 2018, 5:07 AM
Googel
Googel - avatar
+ 3
Do you mean that you want to output the + sign directly? Like showing 1+1 in the alert box?
7th Dec 2018, 5:10 AM
Hanz
Hanz - avatar
0
let sum = 2; alert("1 + 1 = " + sum); you can also use a string template without having to enclose the string in quotes and adding the + to concatenate. the syntax uses the back tick (shift+~) which is not available on my iPhone keyboard so I will use a single quote here. just enclose the entire expression in back ticks. Enclose your variables in ${} and it will be concatenated. alert(‘1 + 1 = ${sum}’)
8th Dec 2018, 2:23 AM
JeremyAxe
JeremyAxe - avatar