-1
I’m trying to answer a question inside a platform, and I’m not being able to adjust the code as the algorithm wants. I am receiving the following errors : 1- You must have an if validating the counter i/ 2- You must print the message "So-and-so resident can use the elevator". Any hint?
Question :
Over the weekend, our building’s elevator broke down, severely restricting the flow of people. Considering this, only the residents of the apartments with even number will be able to use the elevator. Write a code that, based on the variable "residents" in which residents can use the lift. The apartment number is its position in the array, and the resident’s name is the value.
Print the list on the console with the following phrase: 'The resident ' + address name + ' you can use the lift'
// MY CODE :
var moradores = [
"Fulano de Tal",
"Beltrano da Cia",
"Viajante do Tempo",
"Morador da Lua",
"Marciano Azul",
"Et da Eslováquia",
"Jedi do Lado Cinza da Força",
"Baby Yoda Amarelo"
]
for ( var i = 0; i < moradores.length; i++){
if( moradores[i] % 2 || moradores[i] == 0){
var nomes = moradores[i]
}
}
console.log("O morador " + nomes + " pode usar o elevador")
I edited to fix a mistake I’d made
– placementw
I appreciate the explanation and the suggestion, I actually modified the code and the terminal is printing correctly, but the algorithm of the platform I’m using still indicates an error : Must have an if validating the i counter . @placementw
– xBrn0xy
@placementw Tbm created a global scope variable without any need!
– LeAndrade
so-and-so is the resident of apartment 1, the couple resident begins with Beltrano da Cia. Does not exist, apartment 0
– user60252
@Thank you Leocaracciolo, that was really the problem.
– xBrn0xy