0

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
  • What errors are you getting? Commented Nov 14, 2013 at 0:09
  • if( ht >= 64). You mean to say if ht is greater than or equal to, not less than. Commented Nov 14, 2013 at 0:10
  • You probably want this: alert("You may go on the ride!!"); Commented Nov 14, 2013 at 0:13

3 Answers 3

0

Remember you want to show a String! You forgot " "

prompt("You may go on the ride!!");
Sign up to request clarification or add additional context in comments.

Comments

0

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

Thank you. I am still getting an alert: TypeError: 'undefined' is not an object (evaluating 'document.getElementById("height")[0].value')
It is also sending me an error about the function ride. Is there a better way to call the function other then onclick?
0

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; 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.