+ 1

Quiz

Hi , So I’m trying to create a quiz in html that you have to enter sentences and I do far created the quiz part and it tells u if you got it wrong or not but I want to create a part like if you put I like candies and candies should be chocolate and I want to show that only candy is wrong in the sentence. Can anybody help me? Thanks!!

7th Dec 2019, 11:21 PM
Rich Lai
2 RĂ©ponses
+ 1
// you would know how to get this part better than I since you know what the rest of the sentence should look like. var theSubstringThatShouldBeChocolate = getTheChocolateSubstring(); // Remove leading and trailing whitespaces. // Convert to lower case if case should't affect the correctness of the answer. theSubstringThatShouldBeChocolate = theSubstringThatShouldBeChocolate.trim().toLowerCase(); if (theSubstringThatShouldBeChocolate !== 'chocolate') { alert(theSubstringThatShouldBeChocolate + " should have been chocolate."); } else { // The chocolate part was correct but // continue checking more of the answer. } The above would show text to the user explaining when chocolate was expected but I would likely also echo the answer they gave back to them. This could show the incorrect non-chocolate word with red text span and might use the title attribute to explain what is expected instead. Consider using multiple choice whenever possible. Free text doesn't give people a strong enough structure to follow when answering automatically graded questions. A trivial example to illustrate how difficult free text is to grade is that the user could answer in upper or lower case for your questions and essentially be correct in both cases but you'd need to program that rule by converting everything to the same case. Leading, trailing, and doubled whitespaces can also be a problem that you need to trim away. Little typos are far worse to scrape clean. All these problems won't exist if you limit the user to select from predefined choices in a multiple choice format.
9th Dec 2019, 12:36 AM
Josh Greig
Josh Greig - avatar
0
thank you so much!!
9th Dec 2019, 2:16 AM
Rich Lai