JavaScript Getting Started With ES2015 Defining Variables With let and const Review let and const

Vivian Oyemike
Vivian Oyemike
6,586 Points

Hi, Please I need help with the following. Thanks

Complete the code below to create variables scoped to the secondsWorked function:

function secondsWorked(hours); totalTime; minutesInHour = 60; minutesInSecond = 60; totalTime = hours * minutesInHour * minutesInSecond; } console.log( secondsWorked(40) );

1 Answer

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 51,836 Points

You'll make decisions on how you declare based on whether the value will change. This only applies to totalTime. Converting between seconds, minutes and hours involves constants. So

function secondsWorked(hours);
let totalTime;
const minutesInHour = 60;
const minutesInSecond = 60;
totalTime =  hours * minutesInHour * minutesInSecond; 
}
console.log( secondsWorked(40) );

As an aside the constant to convert seconds to minutes should correctly be named secondsInMinute

Vivian Oyemike
Vivian Oyemike
6,586 Points

Thank you for your swift response. I did try to figure it out.