3 ms·
Need some help on Codecademy.com
Hello there, i'm on codecadyme at the JavaScript Quick Guide, but i'm stuck in this one:
http://www.codecademy.com/courses/javascript-intro/3#!/exercises/7
this is what i have to do:
// Example switch statement. typeof returns the type
// of the value as a string. For example, the type of
// a string is 'string', the type of a number is
// 'number', and the type of an object is 'object'.
switch (typeof 'foo') {
case 'string':
// some code
// If you don't return in the block, you should
// always have a break afterwards.
break;
default:
//block
}
// Write a function that uses switch statements on the
// type of value. If it is a string, return 'str'. If it
// is a number, return 'num'. If it is an object, return
// 'obj'. If it is anything else, return 'other'.
and this is what i did :
function detectType(value) {
switch (typeof value) {
case 'string':
return 'str' ;
}
switch (typeof value) {
case 'number':
return 'num';
}
switch (typeof value) {
case 'objet':
return 'obj';
}
default: return "other";
}
return value;
}
</>
I'm a noob, so i don't know whats missing or wrong, would you kind people please help me? thank you.
- iKnowKungFoo 15y agoA switch statement handles multiple cases. You have a switch statement per case. Also, you misspelled "object". https://developer.mozilla.org/en/JavaScript/Reference/Statements/switch https://developer.mozilla.org/en/JavaScript/Reference/Statem...