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
var person = { | |
firstName: 'Zelda', | |
lastName: 'Fitzgerald', | |
introduce: function () { | |
console.log('my name is ' + this.firstName + ' ' + this.lastName) | |
} | |
} | |
// Question 1: Given a greet() function modify it to update its context with an object | |
// having firstName and lastName properties. |
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
// Question 1: Declare an object named "person" with properties "name", "age", and "city" and set their respective values to "John", 30, and "New York". | |
var person = { | |
name: 'John', | |
age: 30, | |
city: 'New York' | |
} | |
console.log('person', person) | |
// Question 2: Declare an object named "book" with properties "title", "author", and "year" and set their respective values to "The Great Gatsby", "F. Scott Fitzgerald", and 1925. Access the "author" property and store its value in a variable called "authorName". | |
var book = { |
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
// 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 | |
} | |
// Question 2: IIFE Function | |
// Write an IIFE (Immediately Invoked Function Expression) that prints "Hello, World!" to the console. | |
;(function () { | |
console.log('hello world') |
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
// Primitive | |
var message = 'hello' | |
var count = 42 | |
var correct = true | |
// Container/Collection | |
// Entity (One thing, multiple attributes) | |
var person = { | |
name: 'Zelda Fitzgerald', |
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 function `greet` that takes a name as a parameter and returns a greeting message. | |
/* | |
function greet (name) { | |
const message = 'Hello ' + name | |
return message | |
} | |
var message = greet('Tallulah') | |
console.log(message) | |
// 2. Write a function `calculateArea` that takes the length and width of a rectangle as parameters and returns its area. |
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 number = 10 | |
var sum = 0 | |
var i = 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
// 1. Write a program that checks if a given number, `num`, is positive, negative, or zero. | |
/* | |
var num = 0 | |
var positive = num > 0 | |
var negative = num < 0 | |
if (positive) { | |
console.log('positive') | |
} else if (negative) { | |
console.log('negative') | |
} else { |
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 |
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 Y. Stephenson' | |
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. |
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
/* | |
var x = 8 - 1 | |
console.log('x', x) | |
var y = 2 + 6 | |
console.log('y', y) | |
var equal = x === y | |
console.log('equal', equal) | |
var notEqual = x !== y | |
console.log('notEqual', notEqual) | |
var greater = x > y |
NewerOlder