I have problems with Javascript on my codes :-( | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

I have problems with Javascript on my codes :-(

https://code.sololearn.com/WYHG0TfI067X/?ref=app

17th Mar 2018, 8:24 PM
Leedor
Leedor - avatar
4 Respuestas
+ 8
https://code.sololearn.com/W6UwZ1nc6JOY/?ref=app sorry for late.. i update ur code..
17th Mar 2018, 8:36 PM
Scooby
Scooby - avatar
+ 5
You have several issues. 1. function shouldn't be capitalized. 2. the ids need to be in quotes. 3. the id for b doesn't match 4. you should move the entire script tag to the bottom of the body so that the DOM has been created and the elements you're trying to access exist - good habit. 5. You need to convert the inputs to int or float etc to perform a mathematical operation on them instead of concatenating them. shoul look like this when done: <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <input id="ipta" /> <input id="iptb" /> <button onclick="plus()">Push</button> <p id="result"></p> <script language="Javascript" type="text/javascript"> function plus() { var a = parseInt(document.getElementById('ipta').value); var b = parseInt(document.getElementById('iptb').value); var c = a + b ; document.getElementById('result').innerHTML = c; } </script> </body> </html>
17th Mar 2018, 8:36 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Thanks guy Lots of mistakes 😅
17th Mar 2018, 9:05 PM
Leedor
Leedor - avatar
+ 1
function has a capital F, should be lower case. I think you also need quotes in your document.getelementbyid parameters
17th Mar 2018, 8:41 PM
Mike Choy
Mike Choy - avatar