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}
;
}
}
console.log(numberDigits(11));