Some practice

This commit is contained in:
2025-11-11 13:16:58 -05:00
parent 243c1e5398
commit 3dd0e1fc22
7 changed files with 9293 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>Week 8 JS Object Practice</title>
</head>
<body>
<h1>Week 8 JS Object Practice</h1>
<script src="index.js"></script>
</body>
</html>

View File

@@ -0,0 +1,63 @@
// Question 1
function person(firstName, lastName, age, city) {
return {
firstName: firstName,
lastName: lastName,
age: age,
city: city
};
}
var testPerson = person("Levi", "McLean", 20, "Woodstock");
console.log(testPerson.firstName);
console.log(testPerson.lastName);
console.log(testPerson.age);
console.log(testPerson.city);
// Question 2
function book(title, author, pages) {
return {
title: title,
author: author,
pages: pages
};
}
var testBook = book("1984", "George Orwell", 386);
console.log(testBook.title);
console.log(testBook.author);
console.log(testBook.pages);
console.log("Update pages to 555");
testBook.pages = 555;
console.log(testBook.pages);
// Question 3
function movie(name, year, rating) {
return {
name: name,
year: year,
rating: rating
};
}
var testMovie = movie("Kill Bill", 2003, 9.5);
console.log(testMovie.name);
console.log(testMovie.year);
console.log(testMovie.rating);
console.log("Adding new property director");
testMovie.director = "Quentin Tarantino";
console.log(testMovie.director);
// Question 4
const playlist = {
name: "Cool Jams",
songs: ["Rap song", "Metal song", "Pop song"]
};
console.log(playlist.songs);
console.log("First Song");
console.log(playlist.songs[0]);
console.log("Last Song");
console.log(playlist.songs[playlist.songs.length - 1]); // Always get last entry
// Question 5

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long