Exercises on the javascript quiz, Schemes and Mind Maps of Computer Science

In order to build up you understanding of the javascript code, try these questions, and add some of your own. Feel free to refer to the text.

Typology: Schemes and Mind Maps

2021/2022

Uploaded on 08/05/2022

nguyen_99
nguyen_99 🇻🇳

4.2

(80)

1K documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Exercises on the javascript quiz
In order to build up you understanding of the javascript code, try these questions, and add some
of your own. Feel free to refer to the text. Keep in mind that many of these are tough questions,
intended to help generate discussions, so don’t worry if you are not sure how to answer them yet.
1. Consider the first call to the handleQuestion function, on line 57 of the code.
a. For each variable below, write what is its value are after line 8 of the handleQuestion code has
executed.
- number
- text
- correctAnswerNumber
- answers
- questionScore
b. Which of these variables store integers? Which store strings (i.e. text)? Which stores an array
of strings?
c. What value does answers[3] have?
d. If userAnswerNumber has value 2, what value does answers[userAnswerNumber] have?
e. The html code produced by the function will be viewed as:
pf3
pf4
pf5

Partial preview of the text

Download Exercises on the javascript quiz and more Schemes and Mind Maps Computer Science in PDF only on Docsity!

Exercises on the javascript quiz

In order to build up you understanding of the javascript code, try these questions, and add some of your own. Feel free to refer to the text. Keep in mind that many of these are tough questions, intended to help generate discussions, so don’t worry if you are not sure how to answer them yet.

  1. Consider the first call to the handleQuestion function, on line 57 of the code. a. For each variable below, write what is its value are after line 8 of the handleQuestion code has executed.
    • number
    • text
    • correctAnswerNumber
    • answers
    • questionScore b. Which of these variables store integers? Which store strings (i.e. text)? Which stores an array of strings? c. What value does answers[3] have? d. If userAnswerNumber has value 2, what value does answers[userAnswerNumber] have? e. The html code produced by the function will be viewed as:

(i) (ii) f. How would you change the function code so that the view would be as in (i) above? g. How would you change the function so that the view would be as in (ii) above?

  1. Suppose that the quiz is to be scored so that –1, rather than 0, is returned when the respondent gives an incorrect answer. How would you change the code to do this?
  2. Find one example of the following in the quiz_results code: an assignment statement, a control flow statement, a variable declaration statement, a variable, a parameter. Which variable is an array variable?
  3. Do you think that the code would behave differently if we changed the variable name userAnswerNumber everywhere to, say, Vancouver?
  4. How might the code be changed to handle a quiz where there may be more than one correct answer, and the user need only select one of these?
  5. Suppose the user answers 2 to the first question and 4 to the second question. Can you trace through the order in which the code is executed in quiz_results, and track how the data values change? (It is very tedious in this case to write down all the lines of code in the order that they are executed, but you should be able to do this in principle.)
  6. Some quizzes, like personality quizzes, assign a score to each question and the feedback at the end depends on the total score. How might you design such a quiz?
  7. The code is organized so that data about each question are passed as parameters to the handleQuestion function. Another way to organize the code would be to create data about all questions in the handleQuestion function itself. How might this be done? Which organization makes most sense to you?

quiz_result.html; (2 pages)

  1. quiz results

  2. Quiz Results

  3. Thank you for your time.

  4. (tear here and hand in at the end of class) Rate your level of understanding of the quiz code. I really don’t follow it at all I have some idea of what it is doing I understand it well enough to make some small changes I have a very good understanding of the code Can you say what aspect of the code is still most confusing? What might help you understand the code better?