Skip to content

Instantly share code, notes, and snippets.

@TiagoDanin
Created February 3, 2018 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TiagoDanin/ee7bfd5e83299f8dadeafb8bd50fdff4 to your computer and use it in GitHub Desktop.
Save TiagoDanin/ee7bfd5e83299f8dadeafb8bd50fdff4 to your computer and use it in GitHub Desktop.
Grupo de JavaScript - COD34234
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8" />
<title> Teste JavaScript</title>
<script type="Text/javascript">
function calcular() {
var pontos = 0;
var doc = document.getElementsByName("quiz01");
// Dica¹: Você pode criar a variável 'i' detro do 'for()'
for(var i = 0; i < doc.length; i++){
if (doc[i].checked){
// Dica²: Usando a propriedade 'value' para definir os pontos
pontos = Number(doc[i].value)
}
}
alert(`Total ${pontos} ok`);
}
</script>
</head>
<body>
<h1> 1. Questao 01 </h1>
<input type="radio" name="quiz01" id="n01" value="2"> Vale 2 pts <br>
<input type="radio" name="quiz01" id="n02" value="4"> Vale 4 pts <br>
<input type="radio" name="quiz01" id="n03" value="6"> Vale 6 pts <br>
<input type="radio" name="quiz01" id="n04" value="8"> Vale 8 pts <br>
<input type="radio" name="quiz01" id="n05" value="10"> Vale 10 pts <br> <br> <br>
<div align="center">
<input type="button" id="button" value="calcular" onclick="calcular()">
<input type="button" id="button" value="limpar" onclick="limpar()">
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment