Total output is not shown in textbox | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Total output is not shown in textbox

the total units is not given as an output in the textbox https://code.sololearn.com/WQgQwp59LE8t/?ref=app for all inputs 1 the total units output must be 0.002

7th Jan 2023, 10:51 AM
Zane Vijay Falcao
Zane Vijay Falcao - avatar
7 Answers
+ 2
The line it mentions has: getElementById(...).value The property it tried to access is 'value', which is a valid one for the element, but isn't for null. But why does it try null, instead of the element? The catch: JS code loads before the HTML document. So the 'units' element just doesn't exist when the function runs, and getElement returns null. Solution: wrap all JS code inside a block with onLoad condition. This tells the interpreter to only load the funcions when the page is fully loaded and all elements are there. Check out some web stuff in the Code section to see it running.
7th Jan 2023, 5:54 PM
Emerson Prado
Emerson Prado - avatar
+ 1
The link isn't working in the app. For a working link, tap "+" button, then Code, and select your code. Plus: pls include in the question description a description of your task and your difficulties.
7th Jan 2023, 4:29 PM
Emerson Prado
Emerson Prado - avatar
+ 1
Good. I ran the code, and it gave an error. Did you see it?
7th Jan 2023, 4:36 PM
Emerson Prado
Emerson Prado - avatar
+ 1
Do you understand the error and the cause?
7th Jan 2023, 5:18 PM
Emerson Prado
Emerson Prado - avatar
0
Emerson Prado check now
7th Jan 2023, 4:32 PM
Zane Vijay Falcao
Zane Vijay Falcao - avatar
0
Yeah it didn't get that one before
7th Jan 2023, 4:41 PM
Zane Vijay Falcao
Zane Vijay Falcao - avatar
0
No
7th Jan 2023, 5:44 PM
Zane Vijay Falcao
Zane Vijay Falcao - avatar