0
Why this simple code doesn't work?
I am new learner and being confused why this simple multiplication code doesn't work. Looking forward for advices. thanks. <head> <title>Page Title</title> </head> <body> <p>Number a</p> <input type="number" id="x"> <p>Number b</p> <input type="number" id="y"><br /><br /> <button onclik="multiply()">click Me</button><br /><br /> <p id="z"></p> window.onload = function (){ var a = document.getElementById("x").value; var b = document.getElementById("y").value; var c = document.getElementById("z"); function multiply(){ return a * b; }; c.innerHTML = multiply(); };
2 Answers
+ 3
1. in html you misspelled onclick as onclik
2. get rid of the window.onload function wrapper
3. move everything else inside multiply
4. instead of returning a*b directly set c.innerhtml = a*b
0
thanks Jason Edelson .