Search⌘ K
AI Features

Solution Review: Let's Vote

Understand how to implement a JavaScript function that evaluates voting eligibility by age. Explore input validation, strict mode usage, and conditional logic to return appropriate messages for different age values and data types.

We'll cover the following...

Solution

...
Javascript (babel-node)
'use strict';
const canVote = function(age) {
if(age === 18) {
return 'yay, start voting';
}
if(age > 17) {
return "please vote";
}
return "no, can't vote";
};
console.log(canVote(12));
console.log(canVote("12"));
console.log(canVote(17));
console.log(canVote('@18'));
console.log(canVote(18));
console.log(canVote(28));
...