I'm a beginner in JavaScript and recently learned about the switch statement. I have an exercise where I need to convert numbers 1-10 into words like "one", "two", "three"... This is what I have tried so far:
function sayNum(){
let numberArray = [1,2,3,4,5,6,7,8,9,10]
let word = '';
for(let i=0;i<numberArray.length;i++){
switch(numberArray[i]) {
case 1:
word = 'one';
break;
case 2:
word = 'two';
break;
case 3:
word = 'three';
break;
case 4:
word = 'four';
break;
case 5:
word = 'five';
break;
case 6:
word = 'six';
break;
case 7:
word = 'seven';
break;
case 8:
word = 'eight';
break;
case 9:
word = 'nine';
break;
case 10:
word = 'ten';
break;
}
}
return word;
}
sayNum()