Cambiar estilos

<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<style>
		#no,
		#si {
			display: none;
		}
	</style>
</head>

<body>
	<h1>Ejercicios HTML</h1>
	<p>Calculadora</p>
	<p>
		Introduce tu edad<input type="text" id="edad" placeholder="Introduce tu edad">
	<p><input type="button" onclick="comprobar()" value="Entrar"></p>
	<h1 id="no">No puedes entrar</h1>
	<h1 id="si">P'Alante</h1>
	<script src="js/test.js"></script>
</body>

</html>
function comprobar () {
  const edad = parseFloat(document.getElementById('edad').value)
  if (edad >= 18) {
    document.getElementById('si').style.display = 'inherit'
    document.getElementById('no').style.display = 'none'
  } else {
    document.getElementById('no').style.display = 'inherit'
    document.getElementById('si').style.display = 'none'
  }
}

Publicado por

Avatar del usuario

Juan Pablo Fuentes

Formador de programación y bases de datos