scrimba
Note at 1:39
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

AboutCommentsNotes
Note at 1:39
Expand for more info
index.js
run
preview
console
const ageSelector = document.getElementById("age-selector")
const genreSelector = document.getElementById("genre-selector")

const btn = document.getElementById("btn")
const suggestedMovie = document.getElementById("suggested-movie")

const moviesArr = [
{
name: "Die Hard",
age: "18+",
genre: "Action"
},
{
name: "Love Actually",
age: "18+",
genre: "Romance"
},
{
name: "The Polar Express",
age: "PG",
genre: "Action"
},
{
name: "Shrek",
age: "PG",
genre: "Romance"
}
]

const selectMovie = (age, genre) => {
const movieMatch = moviesArr.filter(movie => {
if (movie.age === age && movie.genre === genre) {
return movie
}
})
suggestedMovie.innerText = movieMatch[0].name
}

// Task:
// - Write a function to select a suitable movie based on the age group and genre provided.
// - Display it in the suggested-movie paragraph when the button is clicked.
btn.addEventListener('click', () => {
selectMovie(ageSelector.value,genreSelector.value)
})
// Stretch goals:
// - Have the function run on each change of the <select> tags.
// - Add more movies/complexity - for example black and white vs color, preferred actors, etc.
Console
/index.html?
LIVE