Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Numbers Working with Numbers Create a Program with Math

Clare Yeadon
Clare Yeadon
5,539 Points

Code not working

Hello, when I run the code below the console is only showing "There are ${SecsPerDay} seconds in a day." Also, I am trying to learn how to use Markdown.

const secsPerMin = 60;
const MinPerHour = 60;
const HourPerDay = 24;
const DayPerWeek = 7;
const WeekPerYear = 52;

const SecsPerDay = secsPerMin * MinPerHour * HourPerDay;

console.log('There are ${SecsPerDay} seconds in a day.');

5 Answers

connor ingold
connor ingold
5,381 Points

Use backticks instead of quotation marks ' '

const secsPerMin = 60;
const minsPerHour = 60;
const hoursPerDay = 24;
const daysPerWeek = 7;
const weeksPerYear = 52;


const secsPerday = secsPerMin * minsPerHour * hoursPerDay;
const hoursPerWeek = hoursPerDay * daysPerWeek;
const minsInYear = minsPerHour * hoursPerDay * weeksPerYear;


console.log(`There are ${secsPerday} seconds in a day.`);
console.log(`There are ${hoursPerWeek} hours in a week.`);
console.log(`There are ${minsInYear} minutes in a year.`);

const yearsAlive = 28 * weeksPerYear;
const secsAlive = secsPerday * daysPerWeek * yearsAlive;
console.log(`I've been alive for more than ${secsAlive} seconds!`);

My solution of the SecondsAlive Challenge

const secsPerMin = 60; const minsPerHour = 60; const hoursPerDay = 24; const daysPerWeek = 7; const weeksPerYear = 52;

const secondsPerDay = secsPerMin * minsPerHour * hoursPerDay;

console.log(There are ${secondsPerDay} seconds in a day.);

const yearsAlive = 25; const secsPerYear = secsPerMin * minsPerHour * hoursPerDay * 365; const secondsAlive = yearsAlive * secsPerYear;

console.log(I've been alive for more than ${secondsAlive} seconds!);

connor ingold
connor ingold
5,381 Points

Might be of out the scope of this but you could also define your variables like so:

const secsPerMin = 60, 
MinPerHour = 60, 
HourPerDay = 24, 
DayPerWeek = 7, 
WeekPerYear = 52;

const SecsPerDay = secsPerMin * MinPerHour * HourPerDay;

console.log(`There are ${SecsPerDay} seconds in a day.`);