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 trial

JavaScript JavaScript Numbers Working with Numbers Treating Strings As Numbers

Why this did not happen when we worked with multiplying seconds with minutes

Why this did not happen when we worked with multiplying seconds with minutes

1 Answer

While multiplying numbers there were created variables which by type were numbers

const secondsPerMin = 60;
// Notice no quotation marks. That means type of variable is number.

However when you use prompt() even if you type in number to the input field the prompt() function returns value as a string type (means that value you get from it is inside single quotation marks). When adding strings they just get stuck together because program doesnt see that as numbers (so in case of '10' + '5' you get '105')

const HTMLBadges = prompt('How many HTML badges you have?');
/* Returns value in a string type. 
Even if you type in number lets say 10 
prompt will return value of '10' (notice quotation marks). 
So in this case 2 prompt values gonna stick to each other like its a string. 
Thats why '10' + '5' you get '105'
*/
Elfar Oliver
Elfar Oliver
3,924 Points

So if we were to use the typeof method he used at the end of the video in the age calculation, we'd see the difference?