Hack 1: Check Voting Eligibility
Description: This hack checks if a person is eligible to vote based on their age.
- Define a function named
checkVotingEligibilitythat takes one parameter calledage. - Inside the function, use an
ifstatement to check if the age is 18 or older.- Return the message
"You are eligible to vote!"if true; otherwise, return"You are not eligible to vote yet.".
- Return the message
Call the function with different age values to test your work
Hack 2: Grade Calculator
Description: This hack assigns a letter grade based on a numerical score.
- Define a function named
getGradethat takes one parameter calledscore. - Use
if...else if...elsestatements to determine the letter grade based on the score:- Return
"Grade: A"for scores 90 and above. - Return
"Grade: B"for scores between 80 and 89. - Return
"Grade: C"for scores between 70 and 79. - Return
"Grade: F"for scores below 70.
- Return
Call the function with different scores to test your work.
Hack 3: Temperature Converter
Description: This hack converts temperatures between Celsius and Fahrenheit.
- Define a function named
convertTemperaturethat takes two parameters:value(the temperature) andscale(either “C” or “F”). - Use an
ifstatement to check the scale:- If it’s “C”, convert the temperature to Fahrenheit using the formula
(value * 9/5) + 32and return the result with"°F". - If it’s “F”, convert to Celsius using
(value - 32) * 5/9and return the result with"°C". - If the scale is neither, return an error message.
- If it’s “C”, convert the temperature to Fahrenheit using the formula
Test the function with different values and scales to check your work