Hi everyone,
I am working through the Full Stack course. I have a question on one of the code challenges in JS
Could someone tell me if/why one is more acceptable than the other? My code seems to solve the problem but is leaving out the let numString function. It seems unessesary to me
MY CODE:
// Create function here
const numberDigits = x => {
if (x>0 && x < 10){
return `One digit ${x}`;
}else if (x>0 && x < 100){
return `Two digits ${x}`;
}else{
return `The number is: ${x}`;
}
}
console.log (numberDigits(-1))
ANSWER CODE:
// Create function here
const numberDigits = x => {
let numString = '';
if (x >= 0 && x <= 9){
numString = 'One digit: ' + x;
}else if (x >=10 && x <= 99){
numString = 'Two digits: ' + x;
}else {
numString = 'The number is: ' + x;
}
return numString;
}
Thank you so much for the information in advance!