JavaScript Topics
Day 10 :
Array:
var sweetBox = ["Mango Crunch", "Oreo Crunch", "Kesar Crunch", "Orange Apricot Crunch"];
sweetBox.push("Rose Kaju Crunch")
sweetBox.unshift("Cherries Crunch")
sweetBox.pop()
sweetBox.shift()
array.splice(index, elements to be removed, elements to be added)
sweetBox.splice(0,1,"Lemon Crunch", "Kiwi Crunch")
console.log(sweetBox)
var sweetBox = ["Mango Crunch", "Oreo Crunch", "Kesar Crunch", "Orange Apricot Crunch",123,143,133, true, false];
Object:
var student = {
name:"Hema",
age:21,
isStudent:true,
studentAge:23
}
student.course = "FSWD"
student.age = 22
delete student.isStudent;
student["course"] = "FSWD";
student["age"] = 23;
delete student["isStudent"];
var studentAge = "age";
console.log(student.studentAge)
console.log(student[studentAge])
Tasks:
Array Task: Shopping List
Create a JavaScript program that simulates a simple shopping list. Use an array to represent the items in the list.
Your program should perform :
Create an Array:
Create an array called shoppingList with some initial items.
Display Shopping List:
Write a function that takes the shopping list array as a parameter and displays the list of items.
Add Item:
Write a function that takes the shopping list array and a new item as parameters. Add the new item to the shopping list.
Remove Item:
Write a function that takes the shopping list array and an item to remove as parameters. Remove the specified item from the shopping list.
Object Task: Student Information
Create a JavaScript program that manages information about students. Each student should have the following properties:
Name
Age
Grade Level
Subjects (an array of subjects the student is studying)
Your program should perform :
Create an Object:
Create an object called student with properties for a sample student.
Display Student Information:
Write a function that takes a student object as a parameter and displays its information (name, age, grade level, and subjects).
Update Property:
Write a function that takes a student object, a property name, and a new value as parameters. Update the specified property of the student with the new value.
Add Subject:
Write a function that takes a student object and a new subject as parameters. Add the new subject to the student's list of subjects.
Interview Questions:
1. What is the difference between splice() and slice()?
2. How do you add a new property to an object?
No comments:
Post a Comment