I'm able to run it, fill out both Arrays, then input the search criteria but that's it. no results are thrown back.
var SIZE = 4;
var actors = new Array(SIZE); //array holding actors
var roles = new Array(SIZE); //array holding roles
for (var i = 0; i < SIZE; i++) {
actors[i] = prompt ("Please enter your " + (i + 1) + " favorite Actor");
roles[i] = prompt ("What role did your " + (i + 1)+ " Actor played?");
}
var favorite; // hold search actor name
var found = false;
var BR = "<br>";
favorite = prompt ("Please enter the name of your most favorite actor of all");
while (i < size && !(found)) {
i++;
if (actors[i] == favorite) {
found = true;
document.write("Your favorite actor " + actors[i] + " played the role of " + roles[i] + BR);
/*for(var i = 0; i < size; i++) {
if ( favorite == actors[i]) {
found = true;
document.write("Your favorite actor " + actors[i] + " played the role of " + roles[i] + BR);
}
}
*/
if (!found) { //if we find nothing
document.write("Sorry, we couldn't find an actor with that name" + BR);
}
I have tried using for and also while loop but none work, in my head the while loop makes sense. So im not sure whats the issue.
You have to update some parts:
i in the second loopvar SIZE = 4;
var actors = new Array(SIZE); //array holding actors
var roles = new Array(SIZE); //array holding roles
for (var i = 0; i < SIZE; i++) {
actors[i] = prompt("Please enter your " + (i + 1) + " favorite Actor");
roles[i] = prompt("What role did your " + (i + 1) + " Actor played?");
}
var favorite; // hold search actor name
var found = false;
var BR = "<br>";
favorite = prompt("Please enter the name of your most favorite actor of all");
let k = 0
while (k < SIZE && !found) {
if (actors[k] == favorite) {
found = true;
console.log(
"Your favorite actor " +
actors[k] +
" played the role of " +
roles[k] +
BR
);
if (!found) {
//if we find nothing
console.log("Sorry, we couldn't find an actor with that name" + BR);
}
}
k++;
}
found the problem thanks to @Teemu, a silly mistake I made
had SIZE declared but later down I was using size.