-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
Your code works, but the character parameters, movies, releases are off. If you remove them and call movie(3) you see that you get the right result. Or don’t set these arrays in the function and receive them by parameter
– Isac
This answers your question? Develop a function that concatenates elements of the same position in different arrays according to a given condition
– Leo Letto
I tried as I said, I looked at the link indicated, but still with the same error... :(
– Oliveira