Created
September 13, 2025 17:08
-
-
Save davidystephenson/0939fa19a93386a2026eee04e1f3ed0b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| // 1. Write a JavaScript expression to calculate the sum of two numbers, `num1` and `num2`. | |
| var num1 = 10 | |
| var num2 = 11 | |
| var sum = num1 + num2 | |
| console.log(sum) | |
| // 2. Write a program to calculate the area of a rectangle given its length and width. | |
| var length = 5 | |
| var width = 10 | |
| var area = length * width | |
| console.log(area) | |
| // 3. Write a program to calculate the remainder when a given number, `dividend`, is divided by another number, `divisor`. | |
| var divided = 25 | |
| var divisor = 8 | |
| var remainder = 25 % 8 | |
| console.log(remainder) | |
| // 4. Write a program to increment a variable, `count`, by 1. | |
| var count = 0 | |
| count = count + 1 | |
| console.log(count) | |
| // 5. Write a program to concatenate two strings, `str1` and `str2`, using the concatenation operator (+). | |
| var first = 'Tallulah' | |
| var last = 'Bankhead' | |
| var full = first + ' ' + last | |
| console.log(full) | |
| // 6. Write a program to negate a boolean value, `isTrue`. | |
| var isTrue = true | |
| var isFalse = !isTrue | |
| console.log(isFalse) | |
| // 7. Write a program to check if a given number, `num`, is between 10 and 20 (inclusive). | |
| var num = 15 | |
| var atLeast10 = num >= 10 | |
| var atMost20 = num <= 20 | |
| var between = atLeast10 && atMost20 | |
| console.log(between) | |
| // 8. Write a program to check if a person is eligible for a discount based on the age (`age`) and membership status (`isMember`). The discount is applicable if the person is at least 60 years old or is a member. | |
| var age = 65 | |
| var isMember = false | |
| var atLeast60 = age >= 60 | |
| var discount = atLeast60 || isMember | |
| console.log(discount) | |
| // 9. Write a program to check if a given number, `num`, is not equal to 0. | |
| var num = 5 | |
| var not0 = num !== 0 | |
| console.log(not0) | |
| // 10. Write a program to check if a student is eligible for a scholarship based on their grade (`grade`) and attendance (`attendance`). The student is eligible if their grade is at least 90 or their attendance is at least 95%. | |
| var grade = 80 | |
| var attendance = 0.99 | |
| var goodGrade = grade >= 90 | |
| var goodAttendance = attendance >= 0.95 | |
| var scholarship = goodGrade || goodAttendance | |
| console.log(scholarship) | |
| // 11. Write a program to check if a given string, `str`, is either "apple" or "banana". | |
| var str = 'olives' | |
| var isApple = str === 'apple' | |
| var isBanana = str === 'banana' | |
| var appleOrBanana = isApple || isBanana | |
| console.log(appleOrBanana) | |
| // 12. Write a program to check if a given number, `num`, is both positive and even. | |
| var num = 4 | |
| var positive = num > 0 | |
| var remainder = num % 2 | |
| var even = remainder === 0 | |
| var positiveAndEven = positive && even | |
| console.log(positiveAndEven) | |
| // 13. Write a program to check if a person is eligible to vote based on their age (`age`) and citizenship (`isCitizen`). The person is eligible if they are at least 18 years old and a citizen. | |
| var age = 20 | |
| var citizen = true | |
| var atLeast18 = age >= 18 | |
| var vote = atLeast18 && citizen | |
| console.log(vote) | |
| // 14. Write a program to check if a given number `num` is out of range of 0 and 100, is either less than 0 or greater than 100. | |
| var num = 150 | |
| var lessThan0 = num < 0 | |
| var greaterThan100 = num > 100 | |
| var outOfRange = lessThan0 || greaterThan100 | |
| console.log(outOfRange) | |
| */ | |
| // 15. Write a program to swap 2 numbers | |
| var a = 5 | |
| var b = 10 | |
| var placeholder = a | |
| a = b | |
| b = placeholder | |
| console.log(a) | |
| console.log(b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment