Programming a movie function - Characters

Asked

Viewed 1,154 times

-3

Program a movie function that receives three arrays with the names of characters, movies and year of debut in the cinema. The role should also receive an id value chosen by the user with a range of 1 up to the maximum size of the arrays provided and return a phrase with the following template: "character is a character from the film that debuted in the cinema at release." If the id value is invalid, the function should return the phrase "This is not a valid option."

Example:

characters = ["Hermione", "Trinity", "Read"] movies = ["Harry Potter", "Matrix", "Star Wars"] lancings = [2001, 1999, 1977] id = 3

You must return the string:

Leia is a character from the movie Star Wars which premiered in the cinema in 1977.


my code:

Function film(characters, movies, releases, id){ var characters = ["Hermione", "Trinity", "Read"] var movies = ["Harry Potter", "Matrix", "Star Wars"] var lancings = [2001, 1999, 1977]

for(id = 2; id < personagens.length; id++)

if (id >= 3) {
  return ("Essa não é uma opção válida.");
  }else{
    id 
  return (personagens[id] + " é um personagem do filme " + filmes[id] + " que estreou no cinema em " + lancamentos[id]) 
  }

}

console.log(film(["Hermione", "Trinity", "Read"], ["Harry Potter", "Matrix", "Star Wars"], [2001, 1999, 1977], 2))

error reotrna:

Errors: An invalid id must returns an error message An invalid id must returns an error message An invalid id must returns an error message An invalid id must returns an error message

1 answer

0

I managed to resolve by reversing the order, no if I put the condition to show the correct answer, leaving the if I made the error message. I didn’t use the for.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.