简体   繁体   中英

questionnaire error when trying to calculate 10 inputs (button becomes unresponsive)

(JS CODE)

function check() {
  let c=0
  const q1=document.quiz.question1.value
  const q2=document.quiz.question2.value
  const q3=document.quiz.question3.value
  const q4=document.quiz.question4.value
  const q5=document.quiz.question5.value
  const q6=document.quiz.question6.value
  const q7=document.quiz.question7.value
  const q8=document.quiz.question8.value
  const q9=document.quiz.question9.value
  const q10=document.quiz.question10.value
  
  if(q1===1) {
    c++
  }
  if(q2===1) {
    c++
  }
  if(q3===1) {
    c++
  }
  if(q4===1) {
    c++
  }
  if(q5===1) {
    c++
  }
  if(q6===1) {
    c++
  }
  if(q7===1) {
    c++
  }
  if(q8===1) {
    c++
  }
  if(q9===1) {
    c++
  }
  if(q10===1) {
    c++
  }
    
  document.write(c)
  
}

(HTML CODE)

<input type="button" name="" value="Enter The Grade Screen!" onclick="check1()"

i'm trying to create a 10 "page" questionnaire which is able to calculate the total score using selected and saved radio buttons and variables. i'm not sure if that is what is causing the issue (too many variables) but the function works with 4 lines (so only calculating 4 questions and checking if they were correct). as soon as i revert it back to it's original 10 question form the button stops responding. could it be due to the complexity of the function as the eslint test has stated?

i have tried to create separate functions that will call both functions and concatenate the result but i cannot get that to work either.

any help is appreciated, thanks.

Your function is called check() but in the HTML, in the onclick, you're calling check1() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM