Create a function numberDigits() that takes the variable x as its only parameter. If the variable x is between 0 and 9, return the string 'One digit:N' , where N is the value of x . If the variable x is between 10 and 99, return the string 'Two digits:N' , where N is the value of x . Any other value of x , including negative numbers, return the string 'The number is:N' , where N is the value of x .
My code would return unexpected results. Iâm obviously doing something wrong here. Some help would be appreciated!
// Create function here
function numberDigits(x) {
if(x => 0 && x <= 9) {
return One digit: ${x};
}
else if(x => 10 && x <= 99) {
return Two digit: ${x};
}
else {
return The number is: ${x};
}
}
Your strings must match the strings specified in the instructions EXACTLY.
Spelling, Spacing, Punctuation etc. much match exactly.
You wrote Two digit: instead of Two digits:
Also, it seems you donât have a space between the colon and the digit. Your returned string seems to be in the format "One digit:N" instead of the specified format "One digit: N"
You are not returning the string from the else block.
// You wrote:
} else 'The number is:' + (x);
// Consider changing to:
} else return 'The number is: ' + (x);
// OR
} else {
return 'The number is: ' + (x);
}
// OR
} else {
return `The number is: ${x}`;
}