+ 2
Please why isn't this code working
please i have a JavaScript code here why doesn't it work https://code.sololearn.com/W6StyhDxdjhR/?ref=app
7 Respuestas
+ 9
https://code.sololearn.com/Wzaybz42pl6K/?ref=app
+ 5
Try the following:
function print() {
var metre=document.getElementById("metre").value;
var result=metre/1000;
var print=document.getElementById ("output").innerHTML=result;
}
Two things with the way you had it.
1) Uppercase 'V' on .value
2) I believe the JS was trying to read the value before the html had loaded, therefore the element didn't exist yet.
+ 4
function print() {
var metre=document.getElementById("metre").value;
var result=metre/1000;
var print=document.getElementById ("output").innerHTML=result;
}
^Move your variables into your function. It's checking the value before it even has a value, so it'll always return undefined. As well, make it .value instead of .Value to correct the syntax error. That should do the trick.
+ 4
tankz guys thats really helped me a lot😎😎😊
+ 3
Me too Fata1 Err0r, I was working it out whilst you two posted. 3x the service here on SoloLearn 😎
At least I know my reasoning was right.
+ 3
tankz guyz once more here is my full code
https://code.sololearn.com/W6StyhDxdjhR/?ref=app
+ 2
I was too slow. :D NGBrains has it typed up for you so you can see it in action.