I started coding in Javascript only a month ago (and I'm in hs) so I'm not at all experienced. I'm stuck on this assignment I have on the website CodeHS. Here is the assignment:
"Write a program that asks the user how far they ran (in miles) and then how long it took them (in minutes), and print out their speed in miles per hour."
I can't seem to figure out how I would be able to convert any random set of miles and minutes into mph without knowing the values?
CodePudding user response:
You could consider utilizing Window.prompt()
:
const miles = prompt("How many miles did you run?", "");
const minutes = prompt("How many minutes did you run for?", "");
const hours = minutes / 60;
const milesPerHour = miles / hours;
console.log(`The speed of the run was ${milesPerHour.toFixed(2)} mph.`);