Created
September 30, 2013 00:15
-
-
Save gerep/6757769 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> | |
<title>Funções JavaScript - Exemplos de uso</title> | |
</head> | |
<body> | |
</body> | |
<script type="text/javascript"> | |
nome = null; | |
soma(1, 2); | |
divisao(1, 2); | |
multiplicacao(1, 2); | |
divisao(1, 2); | |
function soma(x, y) { | |
total = x + y; | |
document.write("O resultado da soma " + x + " + " + y + " é: " + total + "<br/><br/>"); | |
} | |
function divisao(x, y) { | |
total = x / y; | |
document.write("O resultado da divisão " + x + " / " + y + " é: " + total + "<br/><br/>"); | |
} | |
function multiplicacao(x, y) { | |
total = x + y; | |
document.write("O resultado da multiplicação " + x + " * " + y + " é: " + total + "<br/><br/>"); | |
} | |
function subtracao(x, y) { | |
total = x - y; | |
document.write("O resultado da subtração " + x + " - " + y + " é: " + total + "<br/><br/>"); | |
} | |
function pede_nome() { | |
nome = prompt("Por favor digite o seu nome:", "Nome completo"); | |
if (nome){ | |
pede_idade(); | |
} else { | |
pede_nome(); | |
} | |
} | |
function pede_idade() { | |
idade = prompt("Olá " + nome + ", qual a sua idade?"); | |
if (idade) { | |
ano_nascimento = 2013 - idade; | |
resultado = confirm("OK " + nome + ", você nasceu no ano " + ano_nascimento + ", acertei?"); | |
if (resultado) { | |
alert("Maravilha!"); | |
} else { | |
tentar_novamente = confirm("O que?! Errei? Não tem como, a matemática é bem simples, 2013 - " + idade + ", a não ser que você me informou a data errada, posso tentar de novo?"); | |
if (tentar_novamente) { | |
pede_idade(); | |
} else { | |
alert("OK, sem problemas."); | |
} | |
} | |
} | |
} | |
pede_nome(); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment