Trip Planner - JavaScript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Trip Planner - JavaScript

Why doesn't my mpm variable work: function main() { var distance = parseInt(readLine(), 10); //your code goes here var mph = 40 var mpm = (mph*60) console.log(distance/mpm) } but when I manually input the assignment of mpm, which is of course "mph*60" it works just fine: function main() { var distance = parseInt(readLine(), 10); //your code goes here var mph = 40 var mpm = (mph*60) console.log(distance/mph*60) }

20th Apr 2022, 8:15 AM
Mo Hicks
5 Answers
+ 2
First you need to calculate the taken time and convert it into minutes. 360/120(3) and 360/2*60(10800) are different things in programming calculations because of the operators precedence.
20th Apr 2022, 8:58 AM
Simba
Simba - avatar
+ 1
function main() { var distance = parseInt(readLine(), 10); //your code goes here var time = (distance / 40) * 60; //To convert the distance from mph to mpm console.log(time); } The formula will grab the distance, divided by the average (40) this will provide the mph and the task is mpm (miles per minute) and the result of that will be multiplied by 60 (minutes), in order to convert it to minutes. Then, just need to print the variable time, the code will work
2nd Sep 2022, 4:40 PM
Luzardo Lopez
0
Write (distance / (mph*60)) According to Arithmetic priority
20th Apr 2022, 8:58 AM
ahmed kamel
ahmed kamel - avatar
0
Could u explain it a lil bit more, I'm really beginner on this, I'd already running this code and it works. But i don't know how hehe. thanks.
2nd Nov 2022, 12:09 PM
Sir Axlrod
Sir Axlrod - avatar
0
Hi Axlrod, Is just converting from hours to minutes, after being divided by the average (provided).
3rd Nov 2022, 2:58 AM
Luzardo Lopez