trip planner | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 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??

6th Apr 2021, 4:26 PM
Matias Nicolas Elia
Matias Nicolas Elia - avatar
12 Answers
+ 2
Matias Nicolas Elia Please post your code attempt so that someone can help you.
6th Apr 2021, 4:39 PM
CamelBeatsSnake
CamelBeatsSnake - avatar
+ 2
why did you create two identical questions in different languages? leave the English version. help will come in any case
6th Apr 2021, 5:22 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 2
your mistake is that you substitute direct values. don't do that. use the "distance" variable in your formula
6th Apr 2021, 5:24 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 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
6th Apr 2021, 7:32 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 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!
6th Apr 2021, 4:47 PM
Matias Nicolas Elia
Matias Nicolas Elia - avatar
+ 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.
6th Apr 2021, 8:19 PM
CamelBeatsSnake
CamelBeatsSnake - avatar
+ 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); }
7th Sep 2021, 12:04 AM
Barış U.
Barış U. - avatar
0
Is still showing the same, how should i run the code? i mean, introducing just ¨distance¨? it is confuse
6th Apr 2021, 6:57 PM
Matias Nicolas Elia
Matias Nicolas Elia - avatar
0
camelBeats can you please show me your explanation with playground?
7th Apr 2021, 6:55 AM
Matias Nicolas Elia
Matias Nicolas Elia - avatar
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.
7th Apr 2021, 9:34 AM
CamelBeatsSnake
CamelBeatsSnake - avatar
0
I am having problem with that exercise as well even if I done every thing I needed to do.
1st May 2021, 10:16 PM
Dwayne J Lewis
Dwayne J Lewis - avatar
0
create your own new question and attach your own code snippet
2nd May 2021, 12:06 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar