0

Need some guidance

You need to plan a road trip. You are traveling at an average speed of 40 miles an hour. Given a distance in miles as input (the code to take input is already present), output to the console the time it will take you to cover it in minutes. Sample Input: 150 Sample Output: 225

8th Jan 2021, 1:10 PM
Darryl T. Davis
11 Réponses
- 1
Darryl T. Davis Your answer lies in the following formula which you might have seen in a physics class: distance = speed × time So, using this formula, you can write some JS code An implementation for you: const SPEED = 60 //mph const distance = Number(prompt('Enter distance in miles: ')) const timeInMinutes = (distance / SPEED) × 60 //convert hours into minutes console.log(time) I am actually using ES6 syntax here, so that's why I have used the const keyword. And semicolon is not at all necessary (pointing out Alphin K Sajan 's mistake here) Enjoy!! PS. you can replace prompt() with readline()
8th Jan 2021, 1:32 PM
anon
+ 5
Darryl T. Davis There are some syntactical errors in your code like missing of semicolon at end of stmts and Remember you are writing a general program therefore dont use the values in Example given ... Try this : var distance = parseInt(readLine(), 10); distance=distance/40*60; console.log(distance);
8th Jan 2021, 1:19 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 3
Questions 3 // Passes all tests function main() { var amount = parseFloat(readLine(), 10); var rate = parseFloat(readLine(), 10); function convert(amout,rate){ var final=amout*rate; return final; } console.log(convert(amount, rate)); }
17th Nov 2021, 5:38 PM
Nichervan Essa Mahammad
Nichervan Essa Mahammad - avatar
+ 2
Darryl T. Davis Explanation : It will take 150/40 = 3.75 hours to cover the distance, which is equivalent to 3.75*60 = 225 minutes. Hint : 1.First take user input (distance) 2. Convert distance to time in minutes 3. Output distance to screen ... For help with codes , Post your attempt first ....
8th Jan 2021, 1:14 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 2
function main() { var distance = parseInt(readLine(), 10); //your code goes here var distance = 150/40 var time = (3.75 * 60) == 225 console.log(time)
8th Jan 2021, 1:16 PM
Darryl T. Davis
+ 2
function main() { var depth = parseInt(readLine(), 10); //your code goes here var sum = 0; var count = 0; for (i=1;i<depth;i++) { sum=sum+7; count++; if (sum>=depth) { break; } else { sum=sum-2; } } console.log(count); } Best answer for challenge two
17th Nov 2021, 5:33 PM
Nichervan Essa Mahammad
Nichervan Essa Mahammad - avatar
+ 2
Explanation: It will take 150/40 = 3.75 hours to cover the distance, which is equivalent to 3.75*60 = 225 minutes.
24th Oct 2022, 5:30 AM
Raj Makvana
Raj Makvana - avatar
0
ok
8th Jan 2021, 1:14 PM
Darryl T. Davis
0
ok ill give it a shot
8th Jan 2021, 1:20 PM
Darryl T. Davis
0
awesome!!!! 🙏🏾
8th Jan 2021, 1:25 PM
Darryl T. Davis
0
Darryl, very good explanations but unfortunately, the console log still not accepting the result. Thank you for the great detail explanations, anyway.
17th Dec 2021, 7:10 AM
A R
A R - avatar