0
Is there any way to make the code below more dynamic, like when choosing the switch desired he already do the multiplication table?
var num = parseFloat(prompt('Digite um numero'))
var sinalTabuada = prompt('Digite o sinal que desejar descobrir a tabuada')
var indice = 1;
switch(sinalTabuada){
case '+':
while(indice <= 10){
document.write('a soma de ' + num + sinalTabuada + indice + ' = ' + (num 'sinalTabuada' indice) + '<br>'); // transformar o sinalTabuada em operador aritimetico mesmo..
indice++;
}
break;
Maybe the
evalbe what you are looking for. I just recommend that before reading that and that– hkotsubo
Another tip - not directly related - is to give more meaningful names to variables.
sinalTabuadaimplies multiplication, but if the signal can receive any operation, maybe the variable name should besinal,operacao,sinalOperacao, or something like that. The same for the message, which says "The sum of...", but in fact it will not always be the sum. They may seem like silly details, but better names and better messages help when programming and understand what is doing/happening.– hkotsubo
Thanks for the help and tips!
– Hugo Neves