29.9k views
2 votes
write a program that asks the user how far they ran and then how long they ran and prints out their speed in miles per hour javascript

User Rlorenzo
by
5.9k points

1 Answer

11 votes

Answer:

var distance = prompt("How far did you run? in miles");

var time = prompt("How long did you run? in hours");

function calSpeed(miles, hours){

var speed = miles / hours;

console.log(speed,"m/h")

calSpeed(distance, time);

Step-by-step explanation:

The javascript uses the prompt function to get user inputs for the distance and time variables. The calSpeed function calculates and prints out the speed of the runner with the arguments, distance and time.

User BharathRao
by
6.2k points