What does ‘numeric literal’ mean in java script? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What does ‘numeric literal’ mean in java script?

I’m building a calculator with java script and getting the following syntax error as I enter a problem of this type: a * b * c “No Identifiers allowed directly after numeric literal at Line 50.” In my function, where I solve the mathematical problem, I’m taking the string of an input field where you have to enter your question, replace ‘x’ with ‘*’ (and the division symbol with ‘/‘) and simply use eval() to solve it. However, the error shown above occurs if I try to use the html buttons where you insert the characters into the text. When I press ‘=‘ on e.g. ‘5x9x6’ the error is thrown. However if I switch to the keyboard and enter ‘5*9*6’ everything works perfectly. Here Is my function: function calc() { res = document.getElementById('x').value; res=res.replace('x', '*'); res=res.replace('÷', '/'); (line 50): document.getElementById('x').value=eval(res); Here is my code: https://code.sololearn.com/W4TkgSK7hdX3/?ref=app Can anyone explain me, what I’m doing wrong? Thanks.

24th Jul 2019, 5:53 PM
T. Feix
T. Feix - avatar
0 Answers