Solution Review: Let's Vote
Learn how to solve the problem in the previous lesson.
We'll cover the following...
Solution
Run the code below to see the output.
Press + to interact
'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));
Explanation
First, we need to deduce some points from the sample input and output to implement this function.
The function takes age
as input and returns a string depending upon the value of age
.