+ 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
11 Antworten
+ 2
Can you copy and paste the code here?
+ 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
+ 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)
}
+ 1
NaN stands for Not a Number
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();
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.
0
In the sixth line, as you have to find the value of time and not distance, write it as
time = distance/speed
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();
0
I modified it but says in the output "NaN"
0
It works now thanks guys for the help
0
Or try a hack
const main = () => console.log(Math.round(+readLine() / 5))