I cant output the answer | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I cant output the answer

The first project in javascript course is to plan for a road trip and I got every thing going well but what ever I do it does not output the answer I used console.log() output was NaN which i dont know what does that means and when i write document.write() they say document is not defined ... please help

5th Oct 2021, 4:37 AM
Ahmed Saad
11 Answers
+ 2
Can you copy and paste the code here?
5th Oct 2021, 5:18 AM
Ajinkya
Ajinkya - avatar
+ 3
Here is your correct code.... function main() { var distance = parseInt(readLine(), 10); //your code goes here var speed = 40; var time; /*distance = speed * time; yes, this is equation ,but we have to calculate time not a distance, we can get distance value from user input. The reason of printing output NaN is you use undefined value(time) Calculating undefined value with something gives NaN */ time=distance/speed; min = time * 60; console.log(min); } //main(); no need to invoke main function
5th Oct 2021, 8:00 AM
Myo Thuzar
Myo Thuzar - avatar
+ 1
No need to call main Try this: function main() { var distance = parseInt(readLine(), 10); //your code goes here var time, minutes var speed = 40 time = distance/speed minutes = time*60 console.log(minutes) }
5th Oct 2021, 8:00 AM
Ajinkya
Ajinkya - avatar
+ 1
NaN stands for Not a Number
7th Oct 2021, 3:52 AM
enzore
enzore - avatar
0
function main() { var distance = parseInt(readLine(), 10); //your code goes here var speed = 40; var time; distance = speed * time; min = time * 60; console.log(min); } main();
5th Oct 2021, 7:38 AM
Ahmed Saad
0
In code you post here function readLine is undefined, does not exist. Also variable time does not have value, but you try to access it.
5th Oct 2021, 7:47 AM
PanicS
PanicS - avatar
0
In the sixth line, as you have to find the value of time and not distance, write it as time = distance/speed
5th Oct 2021, 7:53 AM
Ajinkya
Ajinkya - avatar
0
function main() { var distance = parseInt(readLine(), 10); //your code goes here var speed = 40; var time; var minutes; time = speed / distance; minutes = time * 60; console.log(minutes); } main();
5th Oct 2021, 7:53 AM
Ahmed Saad
0
I modified it but says in the output "NaN"
5th Oct 2021, 7:54 AM
Ahmed Saad
0
It works now thanks guys for the help
5th Oct 2021, 8:02 AM
Ahmed Saad
0
Or try a hack const main = () => console.log(Math.round(+readLine() / 5))
6th Oct 2021, 8:54 PM
Cdc_429_laB
Cdc_429_laB - avatar