The objective of the program is to return the value that exists in one position of an array or another. The problem is that it returns undefined.
var ONE = ["a1", "b1", "c1", "d1"];
var TWO = ["a2", "b2", "c2", "d2"];
// ONCLICK
function main() {
var p = prompt("Choose the ONE variable array or the TWO variable array");
var l = parseInt(prompt("Choose de position of the value of that array"));
console.log(second(l));
second(p,l);
}
function second(p,l) {
if (p == "ONE")
i = 0;
while (i < 11){
if (ONE[i] == l){
return l;
}
i++;
}
if (p == "TWO")
i = 0;
while (i < 11){
if (TWO[i] == l){
return l;
}
i++;
}
}
second()the first time you call it. Sopwill be defined butlwon't be.secondis called but you do nothing with the returned value..... and your console does not match the line under it,.....