While not working [closed]

0

What I would like to do is a while, where I was previously asked to indicate a name that is included in an array, and finally show me the position of the array where the name is inserted.

The code is as follows:

<script>


var Amigos = newArray ("EVA", "DIANA", "MARIO", "LOLI", "GHEORGHE", "LUCIA");
var Ultimo = Amigos.length;
var Posicion = 0;


var Vbusca=prompt("Introduce el nombre");


while(Amigos[Posicion] != Vbusca && Posicion<Ultimo ){
	Posicion++;
}

if(Amigos[Posicion]==Vbusca){
	alert("La posición donde se encuentra " + Vbusca + "es la posición: " + Posicion);
}

else {
   alert("El nombre que buscas no está en la lista");
}


</script>
    
asked by Mario G. Lucas 14.03.2018 в 17:11
source

1 answer

1

The new array is wrong, you've written it together.

Another way to do it: You can declare an array directly by putting the values in square brackets.

var cars = ["Saab", "Volvo", "BMW"];

ARRAYs JS

var Amigos = ["EVA", "DIANA", "MARIO", "LOLI", "GHEORGHE", "LUCIA"];
console.log("Array: "+Amigos);
var Ultimo = Amigos.length;
var Posicion = 0;

var Vbusca=prompt("Introduce el nombre");
console.log("Escrito: "+Vbusca);

while(Amigos[Posicion] != Vbusca && Posicion<Ultimo ){
	Posicion++;
}

console.log("Escrito: "+Posicion);

if(Amigos[Posicion]==Vbusca){
	alert("La posición donde se encuentra " + Vbusca + "es la posición: " + Posicion);
}

else {
   alert("El nombre que buscas no está en la lista");
}
    
answered by 14.03.2018 / 17:17
source