I am just curious why this simple function is not working. I have looked over everything and still I am getting errors. I just want to see if the person is able to ride the roller coaster. The min height is 64. So anything equal or greater is allowed. Any help would be greatly appreciated.
<!doctype>
<html>
<head>
<meta charset="utf-8">
<title>Are you tall enough</title>
<script type="text/javascript">
function ride(){
var rideMin = 64;
var ht = document.getElementById("height")[0].value;
if( ht <= 64){
prompt(You may go on the ride!!);
}
}
</script>
<style>
.container{
width: 960px;
}
input{
width:250px;
height: 150px;
margin-left: 375px;
}
img{
margin-left: 300px;
max-width: 100%;
width: 40%;
margin-bottom: 100px;
}
h1{
margin-left: 200px;
margin-bottom: 50px;
color: blue;
}
</style>
</head>
<body>
<div class="container">
<h1> Are you tall enough to ride the roller coaster</h1>
<img src="roller.png">
<div class="height">
<input type="text" id="height" placeholder="Please enter your height">
<input type="submit" value="sumbit" onclick=ride()>
</div>
</div>
3 Answers 3
Remember you want to show a String! You forgot " "
prompt("You may go on the ride!!");
Comments
It should be
if( ht >= 64){
not
if( ht <= 64)
and the " " in prompt, you should also consider using alert instead of prompt. prompt accepts an input from the user whereas alert just shows the message.
2 Comments
You should place text in prompt() in parentheses like
prompt("You may go on the ride!!");
Also it should be
ht = document.getElementById("height").value;
document.getElementById("height") does not return a collection since "height" is an id and not a class. If you have declared like
<input type="text" class="height" placeholder="Please enter your height">
and you can use
ht = document.getElementsByClassName("height")[0].value;
alert("You may go on the ride!!");