The goal of this homework is to practice:
- Conditional statements in JavaScript (
if,else if,else) - Comparison and logical operators
- Arrays and their most common methods
Write a function compareWithEquality(a, b) that:
- returns
"Equal"ifa == b - returns
"Not equal"otherwise
👉 Test your function with:
compareWithEquality(5, "5")compareWithEquality(10, 10)compareWithEquality(3, 7)
Write a function compareWithStrictEquality(a, b) that:
- returns
"Strictly equal"ifa === b - returns
"Not strictly equal"otherwise
👉 Test with:
compareWithStrictEquality(5, "5")compareWithStrictEquality(5, 5)
Create a function compareNumbers(a, b) that:
- returns
"a is greater than b"ifa > b - returns
"a is less than b"ifa < b - returns
"a is equal to b"ifa === b
Write a function checkAge(age) that:
- prints
"Minor"if the age is less than 18 - prints
"Adult"otherwise
Write a function gradeScore(score) that:
- returns
"Excellent"ifscore >= 90 - returns
"Good"ifscore >= 70 - returns
"Average"ifscore >= 50 - returns
"Fail"otherwise
Create a function weatherMessage(temperature) that:
- returns
"Very cold"if temperature < 0 - returns
"Cold"if temperature is between 0 and 15 - returns
"Warm"if temperature is between 16 and 25 - returns
"Hot"if temperature > 25
Write a function canAccess(age, hasPermission) that:
- returns
"Access granted"ifage >= 18ANDhasPermission === true - returns
"Access denied"otherwise
Create an array called menuItems containing:
"beef_kebab""roast_chicken""rice""salad"
Print the array to the console.
Create an array restaurantMenu containing:
- an array of main dishes
- an array of desserts
From the array above:
print the first main dish
print the last dessert
Add "soup" to the end of the menuItems array.
Remove the last item from menuItems and print it.
Remove the first item from menuItems and print the updated array.
Add "bread" to the beginning of the menuItems array.
✅ Bonus (Optional)
Create a function that loops through an array and prints each item
Combine arrays + conditionals (example: check if a dish exists in the menu)
📌 Instructions
Use JavaScript only
Test your code using node app.js
Comment your code where necessary