- 3
trip planner
hi team, i solved the firt test case and got correct output, but now i have to solve the second case but if i change the numbers got the first test wrong. how is it work??
12 Réponses
+ 2
Matias Nicolas Elia Please post your code attempt so that someone can help you.
+ 2
why did you create two identical questions in different languages? leave the English version. help will come in any case
+ 2
your mistake is that you substitute direct values. don't do that. use the "distance" variable in your formula
+ 2
no, don't get me wrong, you should not insert a direct distance value (for example, 150) into your formula. replace this value with the "distance" variable the test program will automatically substitute the required value there
+ 1
https://code.sololearn.com/ca22A476a8a1
this one i have run is ok, but now, test 2 if i change the console log value shows me the first test wrong!
+ 1
Matias Nicolas Elia as Ярослав Вернигора(Yaroslav Vernigora) has said, don't hard-code the actual value of 150. A function needs to be reusable. Otherwise, there's no point. Being reusable means being able to handle different values.
This is why in this function there's a variable called "distance". Every time the function is used (e.g. in each test case), the value that "distance" holds will change. That's why you need to use the "distance" variable in your calculation.
So the calculation is basically "distance" divided by the speed multiplied by 60 to get the minutes.
+ 1
function main() {
var distance = parseInt(readLine(), 10);
//your code goes here
function timeCalc(dist, avg) {
let time = dist/avg;
return time * 60;
}
let ans = timeCalc(distance, 40)
console.log(ans);
}
0
Is still showing the same, how should i run the code? i mean, introducing just ¨distance¨? it is confuse
0
camelBeats can you please show me your explanation with playground?
0
Matias Nicolas Elia I just looked at the latest version of your code that you linked above. That's correct. It should pass all the tests.
0
I am having problem with that exercise as well even if I done every thing I needed to do.
0
create your own new question and attach your own code snippet