2013-03-21 2 views
0

문제의 평균 자리 수 즉, 55 + 20 = 0 캐리 수와 총 값 = 75를 확인해야하는 js 프로그램이 있습니다. 수표 응답에 문제가 있습니다. 그것이 무엇인지 알아내는 것 같지 않습니다. 그러나이 방법을 사용하면 올바른 결과를 얻지 못하고 모든 대답이 잘못되었다고합니다.출력의 자바 스크립트 문제

var topNumber = new Array();//top number 
topNumber[1] = "35"; 

var bottomNumber = new Array();//bottom number 
bottomNumber[1] = "20"; 

var answer = Array();//answer 
answer[1] = "55"; 

var carryover = new Array();//carry over number 
carryover[1] = "0"; 

//create arrays to store user information 

var userCarry = []; 

var userAsn = []; 

//creates user values 

var userCarry1 = ""; 

var userAsn1 =""; 

//sets the number of questions to zero 
var qnumber = 0;  
//creates a function to display the page number, math problem, and an alert to save the user name. 
function nextQuestions() { 
    //every time the user clicks on the button the number will increase and will display question number and it will be used to display the rest of the question information. 
    qnumber = qnumber + 1; 
    document.getElementById('questionNumber').value = qnumber; 
     //sets up question numbers with qnumber is equal to a specific question number. 
    switch (qnumber) { 
     case 1: 
     // question number and question 
     document.getElementById('topQuestionNumber').value = topNumber[1]; 
     document.getElementById('bottomQuestionNumber').value = bottomNumber[1]; 
     //creates values to store the user information 
     userCarry1 = document.getElementById('carryOverNumber').value; 
     userAsn1 = document.getElementById('answerNumber').value; 
     break; 


//creates a function that will check if the user value is equal to the answer 

function checkAnswer() { 
    if((answer[1] == userAsn1) && (userCarry1 == carryover[1])) { 
     alert("Your answer is correct!" + userCarry1 + userAsn1); 
    } 
    if((answer[2] == userAsn2) && (userCarry2 == carryover[2])) { 
     alert("Your answer is correct! " + userCarry2 + " "+ userAsn2); 
    } 
    if((answer[3] == userAsn3) && (userCarry3 == carryover[3])) { 
     alert("Your answer is correct! " + userCarry3 + " "+ userAsn3); 
    } 
    if((answer[4] == userAsn4) && (userCarry4 == carryover[4])) { 
     alert("Your answer is correct! " + userCarry4 + " "+ userAsn4); 
    } 
    if((answer[5] == userAsn5) && (userCarry5 == carryover[5])) { 
     alert("Your answer is correct! " + userCarry5 + " "+ userAsn5); 
    } 
    if((answer[6] == userAsn6) && (userCarry6 == carryover[6])) { 
     alert("Your answer is correct! " + userCarry6 + " "+ userAsn6); 
    } 
    if((answer[7] == userAsn7) && (userCarry7 == carryover[7])) { 
     alert("Your answer is correct! " + userCarry7 + " "+ userAsn7); 
    } 
    if((answer[8] == userAsn8) && (userCarry8 == carryover[8])) { 
     alert("Your answer is correct! " + userCarry8 + " "+ userAsn8); 
    } 
    if((answer[9] == userAsn9) && (userCarry9 == carryover[9])) { 
     alert("Your answer is correct! " + userCarry9 + " "+ userAsn9); 
    } 
    if((answer[10] == userAsn10) && (userCarry10 == carryover[10])) { 
     alert("Your answer is correct! " + userCarry10 + " "+ userAsn10); 
    } 
    else { 
     alert("Your answer is wrong."); 
    } 


} 
+0

코드를 통해 디버거를 단계별로. –

+0

switch 문의 끝 괄호는 어디에 있습니까? 그리고 첫 번째 기능? – some

답변

1

내 추측은 변수 유형 덤비는한다는 것이다

topNumber [1] = "35"은 문자열의 조각의 프로그램, int로하지 말

내가 topNumber을 시도 할 것 [1] = 35; 및 parseInt() 비교 사용자 입력 안전

+0

'35 == "35"'사실입니다. 맞습니까? – RobG

+0

나는 그것을 parseint로 시도했다. var userCarry = parseInt (document.getElementByld ('carryOverNumber'). value); 많은 도움이되지 않습니다. – PandaMan

+0

@RobG'35 == "35"', 그러나 '35 + "35"== "3535"' – some