QUESTION IMAGE
Question
if you were given the following variables:
let distance = 2;
let time = 30;
what line of code would print the speed in km/hr if the distance is given in km and the time is given in minutes? (speed = distance / time)
○ console.log(distance / (time / 60));
○ console.log(distance / time);
○ console.log(distance (time 60));
○ console.log(distance * time);
question: 7
what is printed to the screen when the following program is run?
let num = 13 % 3;
console.log(num);
○ 1
○ 2
○ 3
○ 4
First Sub - Question (Code for Speed Calculation)
To calculate speed in km/hr when distance is in km and time is in minutes, we need to convert time from minutes to hours. Since there are 60 minutes in an hour, the time in hours is \( \text{time (minutes)} / 60 \). The formula for speed is \( \text{speed}=\frac{\text{distance}}{\text{time (hours)}}=\frac{\text{distance}}{\text{time (minutes)}/60} \). So the correct code should be console.log(distance / (time / 60));
Step1: Analyze the operation
The code has let num = 13 % 3;. The % operator in JavaScript is the modulus operator, which gives the remainder when the first number is divided by the second.
Step2: Calculate the remainder
When we divide 13 by 3, \( 3\times4 = 12 \), and \( 13-12 = 1 \). So \( 13\%3 = 1 \). Then console.log(num) will print 1.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
A. console.log(distance / (time / 60));