Ask coding questions

← Back to all posts
JavaScript Function Not Going Through
IMightBeMe (33)

I'm trying to make a calculator in HTML to get my JS skills better. I thought I finished everything for addition to work, but when I put in 1 + 1, in the console, it says: ReferenceError: getSolution is not defined at HTMLInputElement.onclick (/:23:69). I don't know what to do about this since I know that both the onclick and the definition of the function are both spelled correctly and that I have linked my JavaScript to my HTML.

Answered by InvisibleOne (3021) [earned 5 cycles]
View Answer
Comments
hotnewtop
InvisibleOne (3021)

The issue is that your script source is looking for index.js but your js file is named script.js
change that on line 31 of your HTML file.

Coder100 (18253)

you got the switch operations wrong.
They look like this:

switch(operation) {
  case "plus":
    // ...
  break;
}

do not forget the break;.

IMightBeMe (33)

Thanks, @Coder100 that fixed it. I'm not marking this as the answer because the question was about the function not being called but thanks for the help nevertheless.

IMayBeMe (484)

Put the script tag linking index.js above the html button and make sure the file names match