Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    please help homework code

    I have a homework page with three schools , four classes, and 4 weeks. Thing is I can't get the assignments to come up in the assignments text area. I can if I only have two if...else conditions, and I have tried three with nesting, but it always comes up undefined. This is for a class assignment but I really need help. I commented out the codes that didn't work. Sometimes i didn't finish the whole code before testing so is that maybe why it didn't work? Must it be complete to work? Thanks in advance for any help.

    I put the whole page in. I am very new to this, and i just can't get my head around it, so any help would be apreciated. It worked if all assignments as long as the assignments were the same for each class of each school.


    Daisey
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>functions</title>
    <script language="javascript">
    
    
    
    function test2(form){
    	/*create a variable*/
    	var varSchool = form.ddlSchool.value
    	var varClass = form.ddlClass.value
    	var varWeek = form.ddlWeek.value
    	
    	var varResults
    	/*create an if statement to determine school*/
    	
    	if (varSchool==0){
    		varSchool = "Prairie High School's ";
    	} else if (varSchool==1){
    		varSchool = "Prairie Middle School's ";
    	} else if (varSchool==2){
    		varSchool = "Prairie Elementary School's ";
    	}
    	
    	if (varSchool==0)
      {
      	if ((varClass==0) && (varWeek==0)){
    		varResults = "000 this code works";
    	}else if ((varClass==0) && (varWeek==1)){
    		varResults = "001 this code works";
    	}else if ((varClass==0) && (varWeek==2)){
    		varResults = "002 this code works";
    	}else if ((varClass==0) && (varWeek==3)){
    		varResults = "003 this code works";
    	}else if ((varClass==1) && (varWeek==0)){
    		varResults = "010 this code works";
    	}else if ((varClass==1) && (varWeek==1)){
    		varResults = "011 this code works";
    	}else if ((varClass==1) && (varWeek==2)){
    		varResults = "012 this code works";
    	}else if ((varClass==1) && (varWeek==3)){
    		varResults = "013 this code works";
    	}else if ((varClass==2) && (varWeek==0)){
    		varResults = "020 this code works";
    	}else if ((varClass==2) && (varWeek==1)){
    		varResults = "021 this code works";
    	}else if ((varClass==2) && (varWeek==2)){
    		varResults = "022 this code works";
    	}else if ((varClass==2) && (varWeek==3)){
    		varResults = "023 this code works";
    	}else if ((varClass==3) && (varWeek==0)){
    		varResults = "030 this code works";
    	}else if ((varClass==3) && (varWeek==1)){
    		varResults = "031 this code works";
    	}else if ((varClass==3) && (varWeek==2)){
    		varResults = "032 this code works";
    	}else if ((varClass==3) && (varWeek==3)){
    		varResults = "033 this code works";
    	}
    		
    		
      }
    else if (varSchool==1)
      {
      if ((varClass==0) && (varWeek==0)){
    		varResults = "100 this code works";
    	}else if ((varClass==0) && (varWeek==1)){
    		varResults = "101 this code works";
    	}else if ((varClass==0) && (varWeek==2)){
    		varResults = "102 this code works";
    	}else if ((varClass==0) && (varWeek==3)){
    		varResults = "103 this code works";
    	}else if ((varClass==1) && (varWeek==0)){
    		varResults = "110 this code works";
    	}else if ((varClass==1) && (varWeek==1)){
    		varResults = "111 this code works";
    	}else if ((varClass==1) && (varWeek==2)){
    		varResults = "112 this code works";
    	}else if ((varClass==1) && (varWeek==3)){
    		varResults = "113 this code works";
    	}else if ((varClass==2) && (varWeek==0)){
    		varResults = "120 this code works";
    	}else if ((varClass==2) && (varWeek==1)){
    		varResults = "121 this code works";
    	}else if ((varClass==2) && (varWeek==2)){
    		varResults = "122 this code works";
    	}else if ((varClass==2) && (varWeek==3)){
    		varResults = "123 this code works";
    	}else if ((varClass==3) && (varWeek==0)){
    		varResults = "130 this code works";
    	}else if ((varClass==3) && (varWeek==1)){
    		varResults = "131 this code works";
    	}else if ((varClass==3) && (varWeek==2)){
    		varResults = "132 this code works";
    	}else if ((varClass==3) && (varWeek==3)){
    		varResults = "133 this code works";
    	}
      }
    else (varSchool==2)
      {
      if ((varClass==0) && (varWeek==0)){
    		varResults = "200 this code works";
    	}else if ((varClass==0) && (varWeek==1)){
    		varResults = "201 this code works";
    	}else if ((varClass==0) && (varWeek==2)){
    		varResults = "202 this code works";
    	}else if ((varClass==0) && (varWeek==3)){
    		varResults = "203 this code works";
    	}else if ((varClass==1) && (varWeek==0)){
    		varResults = "210 this code works";
    	}else if ((varClass==1) && (varWeek==1)){
    		varResults = "211 this code works";
    	}else if ((varClass==1) && (varWeek==2)){
    		varResults = "212 this code works";
    	}else if ((varClass==1) && (varWeek==3)){
    		varResults = "213 this code works";
    	}else if ((varClass==2) && (varWeek==0)){
    		varResults = "220 this code works";
    	}else if ((varClass==2) && (varWeek==1)){
    		varResults = "221 this code works";
    	}else if ((varClass==2) && (varWeek==2)){
    		varResults = "222 this code works";
    	}else if ((varClass==2) && (varWeek==3)){
    		varResults = "223 this code works";
    	}else if ((varClass==3) && (varWeek==0)){
    		varResults = "230 this code works";
    	}else if ((varClass==3) && (varWeek==1)){
    		varResults = "231 this code works";
    	}else if ((varClass==3) && (varWeek==2)){
    		varResults = "232 this code works";
    	}else if ((varClass==3) && (varWeek==3)){
    		varResults = "233 this code works";
    	}
      }
    
    	
    
    	/* make a conditional assignment variable with two conditions class and week*/
    	
    	
    	/*var varscClass
    	if ((varSchool == 0) && (varClass == 0)){
    		varscClass == 0
    	}else if ((varSchool == 0) && (varClass == 1)){
    		varscClass == 1
    	}else if ((varSchool == 0) && (varClass == 2)){
    		varscClass == 2
    	}else if ((varSchool == 0) && (varClass == 3)){
    		varscClass == 3
    	}else if ((varSchool == 1) && (varClass == 0)){
    		varscClass == 4
    	}else if ((varSchool == 1) && (varClass == 1)){
    		varscClass == 5
    	}else if ((varSchool == 1) && (varClass == 2)){
    		varscClass == 6
    	}else if ((varSchool == 1) && (varClass == 3)){
    		varscClass == 7
    	}else if ((varSchool == 2) && ( varClass == 0)){
    		varscClass == 8
    	}else if ((varSchool == 2) && ( varClass == 1)){
    		varscClass == 9
    	}else if ((varSchool == 2) && ( varClass == 2)){
    		varscClass == 10
    	}else if ((varSchool == 2) && ( varClass == 3)){
    		varscClass == 11
    	}*/
    	
    	
    	/*if ((varscClass == 0) && (varWeek == 0)){
    		classWeekassign = "week 1 of reading is read Chapter 1."
    	}else if ((varscClass == 0) && (varWeek == 1)){
    		classWeekassign = "week 2 of reading is complete the Chapter 1 Review, page 20."
    	}else if ((varscClass == 0) && (varWeek == 2)){
    		classWeekassign = "week 3 of reading is read Chapter 2."
    	}else if ((varscClass == 0) && (varWeek == 3)){
    		classWeekassign = "week 4 of reading is complete the Chapter 3 Review, page 40."
    	}else if ((varscClass == 1) && (varWeek == 0)){
    		classWeekassign = "week 1 of math is complete the Chapter 3 Review, page 40."
    	}else if ((varscClass == 1) && (varWeek == 1)){
    		classWeekassign = "week 2 of math is complete the Chapter 3 Review, page 40."
    	}else if ((varscClass == 1) && (varWeek == 2)){
    		classWeekassign = "week 3 of math is complete the Chapter 3 Review, page 40."
    	}else if ((varscClass == 1) && (varWeek == 3)){
    		classWeekassign = "week 4 of math is complete the Chapter 3 Review, page 40."
    	}*/
    	
    	
    	
    	/*do a switch to determine favorite color*/
    	switch(varClass){
    	case "0":
    	varResults = varSchool + "reading assignment for ";
    	break;
    	case "1":
    	varResults =  varSchool + "math assignment for ";
    	break;
    	case "2":
    	varResults =  varSchool + "science assignment for ";
    	break;
    	case "3":
    	varResults =  varSchool + "english assignment for ";
    	}
    	
    	var classWeekassign
    	
    	/*another attempt failed
    	if (varSchool==0) {
       		 if (varClass==0) {
    			 if (varWeek==0){
             classWeekassign = "week 1 is to read Chapter 1."
    			 }
    			 else if(varWeek!=0){
    				
    			 }	
    	     }
             else if((varClass==0) && (varWeek==1)){
             classWeekassign = "week 1 of reading is do the         Chapter 1 Review, page 20."
    	     }
    		 else if((varClass==0) && (varWeek==2)){
             classWeekassign = "week 3 of reading is read         Chapter 2."
    	     }
    		 else if((varClass==0) && (varWeek==3)){
             classWeekassign = "week 4 of reading is do the         Chapter 2 Review, page 40."
    	     }
      }
      else if(varSchool==1){
       
      }
      */
    
    	
    /*Concatenate a string*/	
    varResults = varResults + classWeekassign;
    
    
    /*Write to the page*/	
    form.txtResults.value = varResults + classWeekassign;
    }
    
    </script>
    </head>
    
    <body>
    <form id="myform" action="" method="get">
    <table>
    <tr>
    	<td colspan="2"><p>
    	 <select name="ddlSchool">
    
    	   <option value="0">Prairie High School</option>
    	   <option value="1">Prairie Middle School</option>
           <option value="2">Prairie Elementary School</option>
    	 </select>
         <select name="ddlClass">
           <option value="0">Reading</option>
           <option value="1">Math</option>
           <option value="2">Science</option>
    
           <option value="3">English</option>
       
         </select>
         <br />
    	
    
    	
    	 
    
    	  </p></td>
        </tr>
    <tr>
    	<td width="223"> <select name="ddlWeek">
           <option value="0">Week 1</option>
           <option value="1">Week 2</option>
           <option value="2">Week 3</option>
    
           <option value="3">Week 4</option>
       
         </select></td>
        <td width="147"><input name="btnSubmit" type="button" value="Submit" onclick="test2(this.form)" /></td>
    </tr>
    <tr>
      <td colspan="2"><textarea name="txtResults" cols="50" rows="3"></textarea>&nbsp;</td>
      </tr>
    
    </table>
    
    </form>
    </body>
    </html>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    The most obvious problem is that you are changing the variable varSchool to the actual name of the school:-

    if (varSchool==0){
    varSchool = "Prairie High School's ";
    else if (varSchool==1){
    varSchool = "Prairie Middle School's ";
    }
    else if (varSchool==2){
    varSchool = "Prairie Elementary School's ";
    }

    But then you are attempting to do comparisons based on the number value:

    if (varSchool==0)
    ....
    else if (varSchool==1)
    ....
    but then
    else (varSchool==2) // missing if

    So in every case you get the alert "This code works". But it does not!


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

  • #3
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually I have encountered a problem like that when I was in school. I am so much pressured that I don't know what to do. What I did is to download the code I needed on my homework.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •