Proszę o pomoc.
Kod: Zaznacz cały
// 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;
case 'number':
break;
case 'object':
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'.
function detectType(str, num, obj, other) {
if(typeof === 'string'){
return str;
}
else if(typeof === 'number'){
return num;
}
else if(typeof === 'object'){
return obj;
}
else{
return other;
}
}