Printing Percentage

Asked

Viewed 41 times

0

I tried to make an algorithm to print the percentage of each type of vote, but my code misses for some reason, can anyone explain to me why? Goes below:

/*Escreva um algoritmo para ler o número total de eleitores de
um município, o número de votos brancos, nulos e válidos. Calcular e escrever
o percentual que cada um representa em relação ao total de eleitores.*/

var eleitores = 34
var vbrancos = 16
var vnulos = 8
var vvalidos = 10

vbpercentual = (100 * vbrancos) / eleitores
vnpercentual = (100 * vnulos) / eleitores
vvpercentual = (100 * vvalidos) / eleitores

console.log('Votos em Branco: ' vbpercentual)
console.log('Votos Nulos: ' vnpercentual)
console.log('Votos Válidos: ' vvpercentual)
  • You didn’t create the variables vbpercentual, vnpercentual and vvpercentual. Need to start with the tag var if creating a new variable. Doing it this way works, but it creates implicit global ones, which is bad for your code and if you’re running an automatic validator on a website, it can cause error. Also, to pass more than one argument on console.log() must concatenate with + or comma.

1 answer

0


As we can observe the javascript documentation for functionality console, we can pass several arguments through console.log(), provided that they are separated by a comma.

var eleitores = 34;
var vbrancos = 16;

vbpercentual = (100 * vbrancos) / eleitores;
console.log('Votos em Branco: ', vbpercentual);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.