- 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) }
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.
+ 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
0
Write (distance / (mph*60))
According to Arithmetic priority
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.
0
Hi Axlrod,
Is just converting from hours to minutes, after being divided by the average (provided).