Welcome to the Treehouse Community
Looking to learn something new?
Tracy Lyon4,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));
Dylan Carter1,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.
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.