Javascript Help

spacehead

Beta member
Messages
2
Location
France
<!DOCTYPE html>
<html>
<body>



Age:<input id="age" value="18" />

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction()
{
var voteable;
var age;
age=document.getElementById("age").value; what does .value mean?
voteable=(age<18)?"Too young":"Old enough"; Why are you using the age variabel here?
document.getElementById("demo").innerHTML=voteable;
}
</script>

</body>
</html>
 
While I have no programing experience, it would probably be helpful if you would ask a question or explain the situation instead of just posting code.
 
<!DOCTYPE html>
<html>
<body>



Age:<input id="age" value="18" />

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
function myFunction()
{
var voteable;
var age;
age=document.getElementById("age").value; what does .value mean?
voteable=(age<18)?"Too young":"Old enough"; Why are you using the age variabel here?
document.getElementById("demo").innerHTML=voteable;
}
</script>

</body>
</html>

Yes this isn't very helpful.
Unless your question is those bits in bold but still not very helpful.

The answers are: .value simply gets the value of the element you are looking for.
Why use the age variable? Well technically you don't have to you could just say:
voteable=(document.getElementById("age").value<18)?"Too young":"Old enough";

But sometimes for readability of code it's a good idea to use variables.
 
I don't mean to be a spammer but like others have said are you just asking for members to do this for you or are you posting it for no real reason just wasting time and being a spammer..
 
Back
Top Bottom