Computer Science, asked by creamiepie, 1 year ago

\mathfrak{heya \; mate}

here's my questions:-

1. Write a javascript code to display the message 'Eligible for voting' in a message box, if the following conditions are true:
a. The age should be >= 18
b. The nationality should be Indian.

use the if-else-if statement for this

Answers

Answered by Anonymous
5

Hi


function checkEligibility(age, nationality) {


 // Here we are making sure that age should be greater than OR equal to 18 and nationality should be indian


 // toLowerCase() method is for converting string to lowercase as name suggests


 // because javascript is case sensitive so even if you will pass Indian that will not be equal


 // to indian... that's why I am converting passed nationality to lowercase


 if (age >= 18 && nationality.toLowerCase() == 'indian') {


  // Opening an alert to show message


   alert('Eligible for voting');


 } else {


   alert('NOT eligible for voting');


 }



}



// Here we are calling function with arguments


checkEligibility('20', 'Indian');


 }



}



// Here we are calling function with arguments


checkEligibility('20', 'Indian');

Attachments:
Similar questions