I just can't figure out where the problem is to ask user to insert a number and judge if it's prime, it will be great help since it's my second day learning JavaScript.
<!DOCTYPE html>
<html>
<head>
<title>Prime Checker</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">
var i; result = true;
var n1 = prompt("Please insert a number, I'll check if it's a prime!" , "");
n1 = Number(n1);
if(isNaN(n1))
{
alert("You didn't insert a number, please check again!");
}
else
{
alert("I will check right now");
}
for(i = 2; i < n1; i++)
{
if(n1 % i == 0)
{
result = false;
break;
}
}
if(result == true)
{
alert(n1 "is a prime");
}
else
{
alert(n1 "is not a prime")
}
</script>
</head>
<body>
</body>
</html>