Skip to content

Instantly share code, notes, and snippets.

<script>
// 1. Create a variable `favoriteFruits` and assign it an array of strings representing your favorite fruits.
var favoriteFruits = ['apples', 'grapes', 'olives']
console.log(favoriteFruits)
console.log("\n-------------------------------------------------\n");
// 2. Create a variable `mixedArray` that contains a mix of data types, including numbers, strings, and booleans.
<script>
// Question 1: Anonymous Function
// Write an anonymous function that takes two numbers as parameters and returns their sum.
var add = function (a, b) {
return a + b
}
var sum = add(3, 4)
console.log(sum)
<script>
// Question 1: Anonymous Function
// Write an anonymous function that takes two numbers as parameters and returns their sum.
var add = function (a, b) {
return a + b
}
var sum = add(3, 4)
console.log(sum)
// function greet(person, arriving) {
// if (arriving) {
// console.log('hello', person)
// console.log('how are you?')
// } else {
// console.log('goodbye', person)
// }
// }
// greet('dorothy', true)
// greet('zelda', false)
<script>
var x = 1
var message = 'hi?'
var good = true
var passcodes = {
'back-Door': 3050,
'1wineCellar': 1234,
"2wineCellar": 5678,
nuclearLaunch: 1111,
// 1. Write a JavaScript program that prints the numbers from 1 to 10 using a for loop.
for (var i = 1; i <= 10; i++) {
console.log(i)
}
// 2. Write a JavaScript program that calculates the sum of all numbers from 1 to a given number using a while loop.
var sum = 0
var limit = 5
var x = 1
// 1. Write a program that checks if a given number, `num`, is positive, negative, or zero.
var num = 3
if (num > 0) {
console.log('positive')
} else if (num < 0) {
console.log('negative')
} else {
console.log('zero')
}
// 1. Write a JavaScript expression to calculate the sum of two numbers, `num1` and `num2`.
var num1 = 5
var num2 = 1
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 = 3
var width = 9
var area = length * width
// 1. Declare a variable called `personName` and assign your name to it.
var personName = 'david'
console.log(personName)
// 2. Create a variable `age` and assign your age to it.
var age = 34
console.log(age)
// 3. Create a variable `isStudent` and assign it a boolean value.
var isStudent = false