Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript 2 arrays – printing when they match up Re: 2 arrays – printing when they match up

#140466
Alen
Participant

var priceMyCar = function(car){
var carMake = ;
var carPrice = [500,100,5];

for (var i = 0; i < carMake.length; i++) {
if (carMake === car){
var index = carMake.indexOf(car);
}
if (typeof carPrice[index] != ‘undefined’){
return carPrice[index];
} else{
return ‘No Match’;
}
}
// Call the function passing in argument
console.log(priceMyCar(‘Audi’)); // 500

Hope that helps.