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
// 9. Write a program to reverse an array | |
var letters = ['a', 'b', 'c'] | |
letters.reverse() | |
console.log(letters) |
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
// 8. Write a program to create an array of objects "employees" with properties "name", "age", and "city" and set their respective values to | |
// "John", 30, "New York", "Thomas", 40, "Chicago", "Lily", 35, "San Francisco". Print the name, age, and city of each employee. | |
// Print the name, age, and city of each employee using for..of loop. | |
var employees = [ | |
{ name: 'John', age: 30, city: 'New York' }, | |
{ name: 'Thomas', age: 40, city: 'Chicago' }, | |
{ name: 'Lily', age: 35, city: 'San Francisco' } | |
] | |
for (var employee of employees) { |
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
// 7. Declare an object named "toy" with an empty object as its initial value. | |
// Add the properties "name" and "category" with values "Super Space Rocket" and "Action Figures & Playsets" respectively. | |
var toy = {} | |
toy.name = 'Super Space Rocket' | |
toy.category = 'Action Figures & Playsets' | |
console.log(toy) | |
function describeToy (toy, name, category) { | |
toy.name = name |
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
// 6. Declare an object named "employee" with properties "name", "age", and "city". Delete the "city" property from the object. | |
var employee = { | |
name: 'Zelda', | |
age: 40, | |
city: 'New York' | |
} | |
delete employee.city | |
console.log(employee) |
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
// 5. Declare an object named "person" with properties "name", "age", and "city" and set their respective values to | |
// "John", 30, "New York" and hobbies as "reading", "swimming", "traveling". Print the name, age, and city of the person. | |
var person = { | |
name: 'John', | |
age: 30, | |
city: 'New York', | |
hobbies: ['reading', 'swimming', 'traveling'] | |
} | |
console.log(person.name) |
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
// 4. Write a program to find maximum number in a numeric array. | |
console.log("\n-------------------------------------------------\n"); | |
var numbers = [0, 100, 5] | |
var maximum = numbers[0] | |
for (var number of numbers) { | |
if (number > maximum) { | |
maximum = number | |
} |
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
// 3. Write a program that iterates through each number of an array using for..of loop and computes the sum of squares of each of these numbers. | |
var result = 0 | |
var numbers = [1, 2, 3] | |
for (var number of numbers) { | |
var square = number * number | |
console.log(square) | |
result += square | |
console.log(result) | |
} | |
console.log(result) |
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
// 2. Create a variable `mixedArray` that contains a mix of data types, including numbers, strings, and booleans. | |
var mixedArray = ['hello', 42, true] | |
console.log(mixedArray) |
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. Create a variable `favoriteFruits` and assign it an array of strings representing your favorite fruits. | |
var favoriteFruits = ['olives', 'apples', 'grapes'] | |
console.log(favoriteFruits) |
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
// 8. Arrow Function | |
// Write a function to print a right angle triangle of stars. Use arrow function which takes a number as a parameter that represents the number of lines in the triangle. | |
// * | |
// ** | |
// *** | |
var triangle = (x) => { | |
for (var i = 1; i <= x; i++) { | |
var star = '*' |
NewerOlder