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
11 odpowiedzi
- 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()
+ 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);
+ 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));
}
+ 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 ....
+ 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)
+ 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
+ 2
Explanation: It will take 150/40 = 3.75 hours to cover the distance, which is equivalent to 3.75*60 = 225 minutes.
0
ok
0
ok ill give it a shot
0
awesome!!!! 🙏🏾
0
Darryl, very good explanations but unfortunately, the console log still not accepting the result. Thank you for the great detail explanations, anyway.