Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialWojciech Lipiński
3,421 PointsCan 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
231,248 PointsWith 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
3,924 PointsYou 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!
)