error message

alert(“3 times 4” + equals + v1 * v2); I received an error message so I fixed it to this
alert(“3 times 4 equals” + v1 * v2); and it now works but my question is why does it now work when I moved the “” and removed the + sign?
Thank you I’m just beginning to learn JavaScript

Because in the first one equals doesnt have quotes around it so javascript thinks you are using a variable named equals but because equals doesnt exist as variable you got an error. If you had of looked at the console of your browser you would have seen an error saying so. If you where to write it as alert(“3 times 4 ” + "equals" + v1 * v2); it would have also worked because js would be adding a string and not the value of a variable called equals that didnt exist.

2 Likes

Thank you so much for helping me understand!

2 Likes

Welcome to the forums @asparker :grinning:

Thank you! I’m just learning JavaScript and will probably have many questions

1 Like

We are here to help, so don’t hesitate to ask any question, big or small! :partying_face: