6. I.D., Please Error on this task


#1

I need to print out the three variables types but for somereason I keep receiving this error message.

"Oops, try again. Make sure to fill in the first console.log statement with typeof anObj"

I don't understand it cause my output is actually "object".

Could you please help me out ?

https://www.codecademy.com/courses/objects-ii/1/1?curriculum_id=506324b3a7dffd00020bf661#

// complete these definitions so that they will have
// the appropriate types
var anObj = { job: "I'm an object!" };
var aNumber = 42;
var aString = "I'm a string!";

console.log(typeof(anObj)); // should print "object"
console.log(typeof(aNumber)); // should print "number"
console.log(typeof(aString)); // should print "string"


#2

typeof doesn't require parentheses


#3

console.log(typeofanObj); // should print "object"
console.log(typeofaNumber); // should print "number"
console.log(typeofaString); // should print "string"

I've tried it without it but that is runs on error as well.

I am quite sure the parentheses needed


#4

You need a space between the typeof keyword and the variable you're checking.


#5

look at the example, a space is required (ad mentioned by @toplearner)


#6

Ahh thanks man indeed it does accepts it.

What I don't understand is why codeacademy accepts only this version.
When is Use this one
console.log(typeof(anObj));
it also print out the object so the formula works properly only codeacademy does not accepted it for some reason ...

Or do you know any explanation ? Thanks man


#7

well, you can read this stackoverflow answer, which goes a bit more in depth

although parentheses for typeof is not uncommon, its not the recommended way, which is why the exercise validated as such (i guess, the only person who can answer that question is whomever wrote the course)


#8

ahh okay thanks friend


#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.