I have some code here
var F;
var favv= ['E','I','A','O','U'];
var i = 0;
function vowelcount(arg, favv)
{
for(i=0;i<favv.length;i++) {
c = 0;
V = favv[i];
for (j=0;j<arg.length;j++) {
if (arg[j].toUpperCase()===V) {
c++;
};
}
if (c>0) {
F=V;
return c;
}
}
}
var person1 = {name:"Super",spd:20};
var person2 = {name:"Supeer",spd:20};
function Scheck(person1, person2) {
if (person2.spd>person1.spd) {
var sub=person1;
person1=person2;
person2=sub;
} else if (person2.spd===person1.spd) {
var ct1 = vowelcount(person1.name, favv);
var ct2 = vowelcount(person2.name,F);
if (ct2 > ct1) {
var subp = person1;
person1= person2;
person2=subp;
}
}
console.log(person1);
console.log(person2);
}
Scheck(person1,person2);
console.log(person1);
console.log(person2);
Here I have an Array of vowels, two people with properties name and spd. When I run Scheck, I want to use vowelcount to determine the order that people would move if their Speed stats are equal. If you look at the console.logs inside the function, they print the correct names... but after the function the console.logs print the original order. Why is this?