Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript how to make a test/quiz that is auto graded by javascript

I am a JavaScript noob.
So I am making a quiz on my own website, I originally started making it on Google forms, but it lacks certain features that necessary.
1. The quiz is not multiple choice and some answers will give more than 1 point.
I need to write a function that checks the input text box for strings and if keywords are detected then it will give 1 point or more depending on the answer, however it has to be case-insensitive. For example, if the correct answers are: blue, red, green you would be able to submit: bLUe, RED, green and get 3 points. But typing a correct answer more than once would not give you more points, BLUE, bluE, bLUE, bLuE, BlUe would only give you 1 point not 4.

f9fejrS.png
 
It is not a big deal to scan a string for keywords and add one point for each keyword found. What exactly is your problem with it ? What have you tried already, and where/how did you get stuck ?
 
It is not a big deal to scan a string for keywords and add one point for each keyword found. What exactly is your problem with it ? What have you tried already, and where/how did you get stuck ?


im having trouble with the variable musicscore

its not able to be called in the functions


1650647689856.png











Code:
document.getElementById("music1");

document.getElementById("submit").onclick = answermarker;

document.getElementById("submit").onclick = displayscore;

var musicscore = 0; 

function answermarker() {
  let string = music1.value;
  let answer = string.match(/candy/i);

  if ((string = answer)) {
    musicscore + 1;
//     musciscore++;
  } else {
    musicscore = musicscore;
  }
}

// quiz scores
function displayscore() {
  window.alert(musicscore);
}
 
I'm not sure what you mean with the variable music score its not able to be called in the functions. What is the error or problem with it ?
What I do see is two statements musicscore + 1; and musicscore = musicscore; both of which do absolutely nothing ! Maybe that is your problem ? I see you have commented out musciscore++; which probably would have been correct had you not misspelled the variable name. Seems you replaced an invalid statement by a useless one 😀 My guess is you never looked at the Console log to check for errors like this ? If so, start doing that whenever something does not work like you think it should.

BTW Thanks for posting the code in code tags. That is the right thing to do but there is no point in also posting a screenshot of the same code.
 
I'm not sure what you mean with the variable music score its not able to be called in the functions. What is the error or problem with it ?
What I do see is two statements musicscore + 1; and musicscore = musicscore; both of which do absolutely nothing ! Maybe that is your problem ? I see you have commented out musciscore++; which probably would have been correct had you not misspelled the variable name. Seems you replaced an invalid statement by a useless one 😀 My guess is you never looked at the Console log to check for errors like this ? If so, start doing that whenever something does not work like you think it should.

BTW Thanks for posting the code in code tags. That is the right thing to do but there is no point in also posting a screenshot of the same code.
In code pen if a variable is valid the variable name turns pink but if it's yellow for me. I thought to use musicscore++; but it didn't work, musicscore = musicscore I know would do nothing, I was just seeing if anything would work. I was just trying anything at this point to see what i did wrong.


What I mean is the variable musicscore is defined before the functions and since it's var not let or const it should be able to be used anywhere right??? But it's not.
Code:
var musicscore = 0;

function answermarker() {
  let string = music1.value;
  let answer = string.match(/candy/i);

  if ((string = answer)) {
    musicsore++;
  }
}

// quiz scores
function displayscore() {
  window.alert(musicscore);
}


That what I think I should have but it doesn't work because musicscore value is unchanged by the function
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom