1
function isNumber(n){
if(typeof n == "number"){
return true
} else{
return false
}
}
function contador(){
let numero = document.getElementById('num')
let num = Number(numero.value)
let vet = []
if(isNumber(num)){
alert('É número!!!')
} else{
alert('Não é numero ou não foi digitado um numero')
}
}
body{
background: #D96E48;
}
header{
color: white;
text-align: center;
}
section{
background: white;
border-radius: 10px;
padding: 15px;
margin: auto;
width: 500px;
box-shadow: 3px 3px 15px rgba(0,0,0.363);
}
footer{
color: white;
text-align: center;
font-style: italic;
}
#box{
margin: 0 0 0 125px;
width: 250px;
}
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Contador</title>
<link rel="stylesheet" href="estilo.css">
</head>
<body>
<!-- Cabeçalho -->
<header>
<h1>Contador</h1>
</header>
<!-- Conteúdo Principal -->
<section>
<div>
<p>Digite um numero (1 a 100):
<input type="number" name="num" id="num">
<input type="button" value="resultado" onclick="contador()">
</p>
<p>
<select name="box" id="box" size="10"></select>
</p>
</div>
</section>
<!-- Rodapé -->
<footer>
<p>© CursoemVideo</p>
</footer>
<script src="script.js"></script>
</body>
</html>
Welcome. What exactly is the problem? What error does it make? Have a look at tour for some very useful tips on question formulation. : D
– Ronaldo Araújo Alves
if(isNumber(n))
- in this passage, there is no variablen
defined, try to exchange forif(isNumber(num))
– hkotsubo
Hello, please take a look at a previous post https://answall.com/questions/11275/verifi-se-string-posses-apenas-n%C3%Bameros, this link explains how to use isNaN to know if the string contains only numbers.
– Ricardo Souza