Help with a "nested for loops" challenge

I had a challenge that says :

  • you have an array of these items :

    const items = ["gold cup", "puppy", "sword", "whale's tooth", "squid tentacle", "other"];

    and this array shows items’ price respectively :

    > const prices = [5, 4, 10, 20, 100, 1];

    create a function that calculate the value "the price " of some chosen items which are located in ChosenItem array.
    So I used nested for loop for that. But eventually it didn’t work.
    in the example i had chosen a specific ChosenItem array.
function PricesCalculator() {
let ChosenIems = ["puppy", "sword"];
let price = 0;
for (i = 0; i < ChosenIems.length; i++) {
for (x = 0; x < items.length; x++) {
if (ChosenIems[i] === items[x]) {
price += prices[x];
}
}
}
 
return price;

}

Before taking a deep look at your code, I see that in your nested for loop you wrote

for(x = 0; x < items.length; i++){
....
}

did you mean to increment x after each nested for loop but accidentally put i++?

Ah, it was a typing mistake, i had already corrected it.
thanks for the note.
the console says price is not defined.

what’s the whole code you have in the editor?

it all there

const items = ["gold cup", "puppy", "sword", "whale tooth", "squid tentacle"];
const prices = [5, 4, 10, 20, 100, 1];
  let TotalPrice = 0;
   let ChosenIems = ["puppy", "sword","eagle eye"];
function PricesCalculator() {
  for (i = 0; i < ChosenIems.length; i++) {
    for (x = 0; x < items.length; x++) {
      if (ChosenIems[i] === items[x]) {
        TotalPrice += prices[x];
      }
             else   if (ChosenIems[i] !== items[x]) {
        TotalPrice += 1;
      }
  
    }

  }

  
  return TotalPrice;

}
console.log(PricesCalculator(), );

I get i is not defined - remember to declare all your variables

also note that your else if will execute any time that is true, meaning you get the wrong price at the end

maybe moving that

or using something different, using array methods (indexOf for example), makes it easier to solve with a single loop