Currently, I have a program that is designed to create a new array from an existing array of objects by asking specific questions. However, there seems to be an issue with the recognition of the if
statement within the for
loop when the program runs. The resulting new array contains everything from the old array.
function verb(first, second, third, fourth, conjugation, chapter) {
this.first = first;
this.second = second;
this.third = third;
this.fourth = fourth;
this.conjugation = conjugation;
this.chapter = chapter;
}
var family = new Array();
family[0] = new verb("amo","amare","amavi",'amatum',1,1);
family[1] = new verb("moneo","monere","monui","monitum",2,1);
//remaining array elements...
var choose = prompt("Do you want principle parts?");
var chap_beg = prompt("What chapter do you want to begin?");
var chap_end = prompt("What chapter do you want to end");
var helparray = [1,2,3,4,5,6];
var person = helparray[Math.floor(Math.random() * helparray.length)];
var randselect = [];
for(i=0; i<family.length; i++) {
if(chap_beg < family[i].chapter && family[i].chapter < chap_end) {
console.log(family[i].first);
randselect.push(family[i]);
} else {
console.log("no");
}
}
var rand = randselect[Math.floor(Math.random() * (randselect.length - 1))];
This results in:
amo
moneo
a
debeo
do
servo
conservo
terreo
valeo
video
voco
habeo
satio
culp
ceno
maneo
supero
tolero
audeo
neco
ago