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

Wojciech Lipiński
Wojciech Lipiński
3,421 Points

Can I do the same thing with the alert()?

when I have used this code: const secondsPerMinute=60; const minutesPerHour=60; const hoursPerDay=24; const daysPerweek= 7; const weeksPeryear= 52; const yearsIlived= 34;

const secondsIlived= secondsPerMinute*minutesPerHour*hoursPerDay*daysPerweek*weeksPeryear*yearsIlived;

console.log(I have lived longer than ${secondsIlived} seconds);

It worked just fine, but when I try: alert(I have lived longer than ${secondsIlived} seconds) nothing happens, why is this? thx

2 Answers

Steven Parker
Steven Parker
216,851 Points

With alert, the message should pop up in a little box in front of the browser window.

Are you perhaps working with this code without a browser (like with node.js)?

Elfar Oliver
Elfar Oliver
3,899 Points

You can compare notes here. I got it to work in an alert box

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

const secondsPerDay = secsPerMin * minsPerHour * hoursPerDay; console.log(There are ${secondsPerDay} seconds in a day.)

const age = 25; const yearsAlive = secsPerMin * minsPerHour * hoursPerDay * daysPerYear * age; alert(I've been alive for more than ${yearsAlive} seconds!)