Skip to content

Instantly share code, notes, and snippets.

@katio
Created July 3, 2021 07:44
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 katio/5e3bc185324e3a729f9d65566a6e7da8 to your computer and use it in GitHub Desktop.
Save katio/5e3bc185324e3a729f9d65566a6e7da8 to your computer and use it in GitHub Desktop.
Código de video número 28 de la serie Programación desde cero. Condicionales en JavaScript: if...else: https://www.youtube.com/watch?v=txFTstj87pE&list=PLZCwI0BeUWWK9xfJY9bO36_DG4QtXJX0o&index=28 https://twitter.com/abrupto
<!DOCTYPE html>
<html>
<head></head>
<body>
<style>
body {
color: green;
font-family: arial;
}
#dado {
font-size: 85px;
}
img {
display: block;
}
button {
margin: 10px;
padding: 10px;
background-color: green;
color: white;
cursor: pointer;
}
</style>
<h1>Dado</h1>
<img src="https://i.imgur.com/AYxOJot.png" alt="Trébol de 4 hojas">
<button id="boton">Lanzar dado</button>
<div id="dado"></div>
<script>
function generarNumeroDado() {
return Math.floor(Math.random() * 6) + 1;
}
function lanzarDado() {
dado.innerText = convertirNumeroEnDado(generarNumeroDado());
}
function convertirNumeroEnDado(numero) {
if (numero === 1) {
return '\u{2680}';
} else if (numero === 2) {
return '\u{2681}';
} else if (numero === 3) {
return '\u{2682}';
} else if (numero === 4) {
return '\u{2683}';
} else if (numero === 5) {
return '\u{2684}';
} else if (numero === 6) {
return '\u{2685}';
}
}
boton.addEventListener('click', lanzarDado);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment