Skip to content

Instantly share code, notes, and snippets.

@alanmugiwara
Last active May 6, 2024 15:09
Show Gist options
  • Select an option

  • Save alanmugiwara/b01e14ea3c7da4d24e1f8a5442b1ef87 to your computer and use it in GitHub Desktop.

Select an option

Save alanmugiwara/b01e14ea3c7da4d24e1f8a5442b1ef87 to your computer and use it in GitHub Desktop.
<meta charset="UTF-8">
<script>
function pulaLinha() {
document.write('<br>');
}
function mostra(txt) {
document.write(txt);
pulaLinha();
}
function sorteia () {
return Math.round(Math.random() *20);
}
var n = sorteia();
console.log(n);
var chute = parseInt(prompt('Digite seu chute!'));
while (chute !== n) {
if (chute > n) {
mostra('O número é menor!');
} else {
mostra('O número é maior!');
}
chute = parseInt(prompt('Digite seu chute!'));
}
mostra('Acertou!');
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment