Computer Science, asked by saurav6639, 11 months ago

write a JavaScript code to show eligible to vote​

Answers

Answered by dollurijiju
3

Answer:

JavaScript code to show eligible to vote

Explanation:

<html lang="en">

<head>

<script>

function validate(age){

var ans="not eigible";

if(age>=18){

ans="eligible";

}

return(ans);

}

</script>

</head>

<body>

<script>

var age=parseInt(prompt("Enter age"));

var status=validate(age);

document.write("You are <b>"+status+"</b> for Vote");

</script>

</body>

</html>

Code 2: Input age in body section and print the message through function

<head>

<script>

function validate(age){

var ans="not eigible";

if(age>=18){

ans="eligible";

}

document.write("You are <b>"+ans+"</b> for Vote");

}

</script>

</head>

<body>

<script>

var age=parseInt(prompt("Enter age"));

validate(age);

</script>

</body>

</html>

Code 3: Input age from the function and print the message in body section

<html lang="en">

<head>

<script>

function validate(){

var age=parseInt(prompt("Enter age"));

var ans="not eigible";

if(age>=18){

ans="eligible";

}

return(ans);

}

</script>

</head>

<body>

<script>

var status=validate();

document.write("You are <b>"+status+"</b> for Vote");

</script>

</body>

</html>

Code 4: Input age from the function and printing the message from the function also

<html lang="en">

<head>

<script>

function validate(){

var age=parseInt(prompt("Enter age"));

var ans="not eigible";

if(age>=18){

ans="eligible";

}

document.write("You are <b>"+ans+"</b> for Vote");

}

</script>

</head>

<body>

<script>

validate();

</script>

</body>

</html

Answered by Anonymous
3

<html lang="en">

<head>

   <script>

       function validate(){

           var age=parseInt(prompt("Enter age"));

           var ans="not eigible";

           if(age>=18){

               ans="eligible";

           }

           return(ans);

       }

   </script>

</head>

<body>

   <script>

       var status=validate();

       document.write("You are <b>"+status+"</b> for Vote");

   </script>

</body>

</html>

Similar questions