0
I have a college job to do where you ask the user to enter a number between 0 and 999 and the algorithm must print the entered value in full. I was asking the teacher for help today and he told me to do it using string, where each number typed gets in position and then the program compares these values. The problem is I’m not getting it.
I made this code below only it is not printing the values correctly and is unfinished
var n = (prompt("Digite um número: "));
		
		var pos_c = parseInt(n[0]); //Centena
		var pos_d = parseInt(n[0]); // Dezenas
		var pos_u = parseInt(n[0]); //Unidade
		var pos_e = parseInt(n[1]); //Especiais
		var unidades=["Zero", "Um", "Dois", "Três", "Quatro", "Cinco", "Seis", "Sete", "Oito", "Nove"];
		var especiais=["Onze", "Doze", "Treze", "Catorze", "Quinze", "Dezeseis", "Dezsete", "Dezoito", "Deznove"]; 
		var dezenas=["Dez"," Vinte", "Trinta", "Quarenta", "Cinquenta", "Sessenta", "Setenta", "Oitenta", "Noventa"];
		var centenas=["Cem", "Duzentos", "Trezentos", "Quatrocentos", "Quinhetos", "Seiscentos","Setescentos","Oitocentos", "Novecentos"];
		/*Irá verificar o tamanho vetor e em seguida fará testes para descobrir a centena,dezena e unidade do número*/
		//Imprimir unidadades
		if(n.length === 1) {
			if (n[0]== '0'||'1'||'2'||'3'||'4'||'5'||'6'||'7'||'8'||'9') {
				document.write(unidades[pos_u]);
				}
			}
		else if(n.length === 2) {
			//Números entre 20 e 99
			if(n[0]=='2'||'3'||'4'||'5'||'6'||'7'||'8'||'9' && n[1]=='1'||'2'||'3'||'4'||'5'||'6'||'7'||'8'||'9') {
				document.write(dezenas[pos_d-1]+" e "+unidades[pos_u+1]);
			}
			//Dezenas
			else if ((n[0]=='1'||'2'||'3'||'4'||'5'||'6'||'7'||'8'||'9') && n[1]==="0") {
				document.write(dezenas[pos_d-1]);
			}
			
			//Imprimir Especiais
			else if (n[0]=='1' && n[1]=='0'||'1'||'2'||'3'||'4'||'5'||'6'||'7'||'8'||'9') {
				document.write(especiais[pos_e-1]);
			}
		}
Is there any other way to do this algorithm?
Possible duplicate of How to turn numeric digits into numbers in full?
– Sam