0

I'm running this program that makes a new array out of an old array of objects based on a few prompt questions. However when I run the program, if statement is not recognized in the for loop. The new array contains everything from the new 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;
}
// Now we can make an array of people
/*var family = new Array();
family[0] = new Person("alice", 40);
family[1] = new Person("bob", 42);
family[2] = new Person("michelle", 8);
// add the last family member, "timmy", who is 6 years old
family[3] = new Person("timmy", 6);*/

var family = new Array();

family[0] = new verb("amo","amare","amavi",'amatum',1,1);
family[1] = new verb("moneo","monere","monui","monitum",2,1);
family[2] = new verb("a  "," a"," a","a ",3,6);
family[3] = new verb("debeo","debere","debui","debitum",2,1);
family[4] = new verb("do","dare","dedi","datum",1,1);
family[5] = new verb("servo","servare","servavi","servatum",1,1);
family[6] = new verb("conservo","conservare","conservavi","conservatum",1,1);
family[7] = new verb("terreo","terrere","terrui","territum",1,1);
family[8] = new verb("valeo","valere","valui","valitum",2,1);
family[9] = new verb("video","videre","vid","visum",2,1);
family[10] = new verb("voco","vocare","vocavi","vocatum",1,1);
family[11] = new verb("habeo","habere","habui","habitum",2,3);
family[12] = new verb("satio","satiare","satiavi","satiatum",1,3);
family[13] = new verb("culp","culpare","culpavi","culpatum",1,5);
family[14] = new verb(" ceno","cenare","cenavi","cenatum",1,5);
family[15] = new verb("maneo","manere","mansi","mansum",2,5);
family[16] = new verb("supero","supweare","superavi","superatum",1,5);
family[17] = new verb("tolero","tolerare","toleravi","toleratum",1,6);
family[18] = new verb("audeo","audere","ausus sum","   ",2,7);
family[19] = new verb("neco","necare","necavi","necatum",1,7);
family[20] = new verb("ago","agere","egi","actum",3,8);

var choose = prompt("do you want principle parts ?");
/*<?php echo $_POST["name"]; ?>




/*family[1] = new verb
family[2] = new verb

family[0].chapter
/*"var doceo = {
    definition:"to teach",
    first:"doceo",
    second:"docere",
    third:"dixi",
    fourth:"doctum"
    chapter:"3""*/

/*chap_beg = document.getElementById("0").submit;
chap_end = document.getElementByID("1").submit;*/

var chap_beg =   prompt("What chapter do you want to begin?");
/*var chap_beg = <?php echo $_POST["name"]; ?>*/
var chap_end = prompt("what chapter do you want too end"); 
/* var chap_end = <?php echo $_POST["name"]; ?>*/
/*if((Math.random())*6<1){
    person = 1;
}else if(1<(Math.random())*6<2){
    person = 2;
}else if(2<(Math.random())*6<3){
    person = 3;
}else if(3<(Math.random())*6<4){
  person = 4;
}else if(4<(Math.random())*6<5){
 person = 5;
}else if(5<(Math.random())*6<5){
    person = 6;
} */


var helparray = new Array();
helparray[1]=1;
helparray[2]=2;
helparray[3]=3;
helparray[4]=4;
helparray[5]=5;
helparray[6]=6;

 var person = helparray[Math.floor(Math.random() * helparray.length)];   



var randselect  = new Array();


for(i=0;i<family.length;i++) {


if( chap_beg < family[i].chapter <  chap_end) {

    console.log(family[i].first);
     randselect.push(family[i]);

  }else{
      console.log("no");
  }

    /* console.log(randselect[randselect.length-1]);*/


}
     var rand = randselect[Math.floor(Math.random() * (randselect.length - 1))];
     /*var rand = randselect[Math.round(Math.random() * (randselect.length - 1))];*/`enter code here`

Yielding

amo
moneo
a  
debeo
do
servo
conservo
terreo
valeo
video
voco
habeo
satio
culp
 ceno
maneo
supero
tolero
audeo
neco
ago
2
  • use && operator when you do this if( chap_beg < family[i].chapter < chap_end) Commented Apr 25, 2014 at 5:07
  • It's docere, docui, doctum. Not dixi, doctum ... Commented Dec 10, 2014 at 16:01

1 Answer 1

1

This line...

if( chap_beg < family[i].chapter <  chap_end) {

Should be

if( chap_beg < family[i].chapter && family[i].chapter <  chap_end) {
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.