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 Convert Strings to Numbers

Tracy Lyon
Tracy Lyon
4,007 Points

Typeof +pi gives an error that typeof is not defined at string to number

I changed pi to pi = +pi, then typed console.log (typeof (pi)) and got the same error listed above. I did check to see if typeof worked in the previous code, with the typeof HTMLBadges and CSSBadges as shown in the video. But I got a series of errors when I tried to change pi as shown in the video.

And I did change const pi to let pi and still got the error

Sorry, had to go back to the workspaces, because it has been a while since this occurred.

error: string-to-number.js:11 Uncaught ReferenceError: typof is not defined at string-to-number.js:11

code: const HTMLBadges = prompt('How many HTML badges do you have?'); const CSSBadges = prompt('How many CSS badges do you have?');

const totalBadges = +(HTMLBadges) + +(CSSBadges); console.log(totalBadges); console.log(typeof +(HTMLBadges), typeof +(CSSBadges));

let pi = '3.14' pi = +pi; console.log(typof( pi));

3 Answers

Dylan Carter
Dylan Carter
1,046 Points

The fix to this is simple and everyone is overthinking it. look at the error. it says typof is not defined, thats because you misspelled typeof, as typof. if you go down to your code youll see your last typeof was misspelled.

Tracy Lyon
Tracy Lyon
4,007 Points

I changed const to let before submitting the question.

Because pi was defined as the const, but when you wrote pi = +pi it's like you are redefining the variable pi again. If you want to use pi to be number just +pi to any function that you need to use.