Hello everyone please help this question? function main() { var distance = parseInt(readLine(), 10); | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Hello everyone please help this question? function main() { var distance = parseInt(readLine(), 10);

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

2nd Jan 2021, 1:35 AM
MK GALAXY
MK GALAXY - avatar
12 Answers
+ 7
harshita anand pandey It is reading input, parsing (converts) it as an integer, and then assigning the value to variable `distance`. readLine() is a function only usable in SoloLearn code coaches. There is no such function (as far as I know) in NodeJs or the Web API. It reads the input and returns it as a string. parseInt() parses the input as integer. The 10 passed as argument is the 'base' or 'radix' of the integer. It basically tells parseInt() that the string will be parsed as a normal integer, like 1, 2, 3, .... Radix of numbers: https://simple.m.wikipedia.org/wiki/Base_(mathematics) parseInt(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt Also, I know this thread is 5 months old now, but if the others who have answered are reading this - DO NOT give direct solutions to code coach problema. They are meant to be solved by a person themself, not by getting the solution from someone else. If you give the solution, how will they learn?
28th Jun 2021, 7:30 PM
XXX
XXX - avatar
+ 2
Can someone explain the first line? what exactly (var distance = parseInt(readLine(), 10); ) is doing in this code?
28th Jun 2021, 9:03 AM
harshita anand pandey
harshita anand pandey - avatar
+ 1
function main() { var distance = parseInt(readLine(), 10); //your code goes here var speed = 40 var time = 60 var minutes = distance/speed console.log(minutes*time) }
1st Apr 2021, 6:06 AM
Apoorva Singh
Apoorva Singh - avatar
+ 1
function main() { var distance = parseInt(readLine(), 10); var speed=40; var timeInHours=distance/speed; var timeInMinutes=(timeInHours*60); console.log(timeInMinutes); }
27th Sep 2021, 2:57 AM
Med Hedi Benkahla
Med Hedi Benkahla - avatar
0
Thank u jamal sir my question is solve
2nd Jan 2021, 11:32 PM
MK GALAXY
MK GALAXY - avatar
0
Thanks for clearing my doubt 😊
29th Jun 2021, 3:05 AM
harshita anand pandey
harshita anand pandey - avatar
0
function main() { var distance = parseInt(readLine(), 10); //your code goes here var speed = 150 var time = 225 var minutes = distance/speed console.log(minutes*time) } Good Luck
25th Jan 2022, 3:00 AM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
0
The basic thing to do here is to find out the number of hours involve in the journey And to put the time in minutes is simple as shown on my code function main() { var distance = parseInt(readLine(), 10); //your code goes here var speed = 40; var time= 60; var hour = distance/speed; console.log(hour*time); }
18th May 2022, 11:26 PM
Tobah
Tobah - avatar
0
function main() { var distance = parseInt(readLine(), 10); var timeInMinutes = (distance /40) * 60 console.log(timeInMinutes) }
22nd Sep 2022, 8:17 PM
Khouloud Mekni
Khouloud Mekni - avatar
0
Hi evecan i get a help with this question here var computers = parseInt(readLine(), 10) //your code goes here
20th Oct 2022, 9:27 AM
Amara
- 1
Please copy the code in the question description and NOT THE TITLE. Or better yet, make a code in the code playground and attach it here.
2nd Jan 2021, 1:59 AM
XXX
XXX - avatar
- 4
This is the solution function main() { var distance = parseInt(readLine(), 10); //your code goes here var speed = 40 var time = 60 var minutes = distance/speed console.log(minutes*time) }
2nd Jan 2021, 10:02 AM
Jamal Saied
Jamal Saied - avatar