Data Abstraction Homework
Quick practice with Javascript Lists
📝 Data Abstraction Hack (10 minutes)
Instructions
In this activity, you’ll learn how lists manage data and reduce complexity in programs. Follow these steps:
- Edit the
students
list to use your own names (friends, classmates, etc.). - Edit the
scores
list to assign each student a score of your choice. - Save and refresh the page in your browser to see how the output changes automatically.
- After experimenting with
students
andscores
, complete the 🚀 Hack Challenge at the bottom. - To make edits, open VS Code and find the file at
notebooks/csp/big-ideas/2025-09-26-bigidea32homework.ipymd
.
Class Roster Output:
🚀 Hack Challenge
Now that you’ve practiced with students
and scores
,
it’s your turn! Create one new list of your choice.
✅ Ideas:
- A list of
favoriteFoods
- A list of
cities
you want to visit - A list of
videoGames
you enjoy
After creating your new list, write a loop to print each element to the page.
// Example structure: let favoriteFoods = ["Pizza", "Burgers", "Sushi"]; for (let i = 0; i < favoriteFoods.length; i++) { console.log(favoriteFoods[i]); // Replace console.log with output to the page if you like }
💡 Hint: Use the same pattern you saw with students
and scores
.
%%javascript
// Hack Challenge: New List of favorite foods
let favoriteFoods = ["Pizza", "Burgers", "Sushi", "Ice Cream"];
// Build output string for the new list
let hackOut = "<h3>Favorite Foods</h3>";
for (let i = 0; i < favoriteFoods.length; i++) {
hackOut += "<p>" + favoriteFoods[i] + "</p>";
}
// Append hack challenge output to the main output div
document.getElementById("output").innerHTML += hackOut;