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. 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 |
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 = 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 |
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 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') | |
} |
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 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 |
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
<script> | |
var x = 1 | |
var message = 'hi?' | |
var good = true | |
var passcodes = { | |
'back-Door': 3050, | |
'1wineCellar': 1234, | |
"2wineCellar": 5678, | |
nuclearLaunch: 1111, |
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
// 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) |
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
<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) |
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
<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) |
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
<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. |
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
let currentQuestion = 0 | |
let score = 0 | |
const numOfQuestions = questions.length | |
const numOfChoices = 3 | |
const questionCountElement = document.getElementById('question-count') | |
function displayQuestion () { | |
const question = questions[currentQuestion] | |
console.log('question', question) | |
const questionElement = document.getElementById('question') |
OlderNewer