Homework!!
Your task is to fill in the following code to alter the arrays!
Lesson 1 Homework
%%js
//We have an array made for you, but something's off...
let desserts = ["lemon","delete1","ice cream","chocolate cake","key lime pie","delete2"];//makes an array with desserts
//We need to get rid of the elements labeled delete1 and delete2!
desserts.pop();//which command gets rid of the last element in the array?
desserts.splice(1,1);//which command will delete the delete 1 element and how do you use it??
//now that that's done... a lemon isn't a dessert unless you're weird... maybe change it to a lemon-themed dessert?
desserts[0]="lemon ice gelato";//re-defines term 0 as lemon ice gelato
//hint for the previous 2 fill-in-the-blanks: the indexing starts at 0
console.log(desserts);//prints desserts
//okay okay, you've proven your skills... now all that's left is to print the list!
<IPython.core.display.Javascript object>
Lesson 2 Homework - Part 1
%%js
//Okay, this will be a little tougher. We can put your knowledge of the second lesson to the test. (ignore that this concept is easy compared to the other lessons lol)
//I want you to create a list of whatever you'd like (integers or strings, it really doesn't matter) and have a repeating element in it. ex: let list = [1,2,3,1,4];
let extracurriculars = ["Odyssey of the Mind", "Quizbowl", "FIRST Robotics Challenge", "Book Club", "Volunteering", "Math Club", "STEMElevate", "FIRST Robotics Challenge"];
//Creates an array with the extracurriculars that I am in
//Ok, now I know this is about arrays, but could you make a for loop to iterate through each element and print the index of them?
for( let extracurricular of extracurriculars){
console.log(extracurriculars.indexOf(extracurricular));//prints out the index(number) in the array that each element is in order
}
//Wait! You remember that repeating element I made you put in your list? Create a separate command outside of the loop to print the index of the last occurring repeated value.
console.log(extracurriculars.lastIndexOf("FIRST Robotics Challenge"));//prints out the index of the last "FIRST Robotics Challenge"
<IPython.core.display.Javascript object>
Lesson 2 Homework - Part 2
%%js
//This is the fairly simple final problem of arrays!
//Create a list here that includes whatever you'd like once again.
let foodILike = ["udon", "ramen", "potatoes", "candy", "cheesecake", "cheese crepes"];//array of food that I like
//Now, print the length of your list! Tip: you don't need to create a variable for the list's length! Just console.log the list.length; it saves you a line :D
console.log(foodILike.length);//prints length of array
//Finally, create a variable to check if a value in your list is included in the list and print that variable you created (it should output true or false)
let inArray = foodILike.includes("ramen"); //Checks if ramen is in the array
console.log(inArray);//prints out inArray (true or false depending on if the specified food is in the array)
<IPython.core.display.Javascript object>
You’re done with your homework!!