Question: While there is no scientific evidence to support it, some people believe in Extra-Sensory Perception or ESP. A standard test for determining whether someone has
While there is no scientific evidence to support it, some people believe in Extra-Sensory Perception or ESP. A standard test for determining whether someone has ESP involves picking a random card from a deck and then asking the subject to guess the card. For example, we might settle on just two cards (e.g., a Two and a Queen), and repeatedly pick one at random. If the subject is able to guess the right card more than 50% of the time, then a claim for ESP might be made. The following HTML document provides a start on implementing such an ESP test.
Card Guessing
I'm thinking of a card... guess what it is:
Number of guesses: 0
Here is the page that is displayed when the above HTML document is loaded in a browser.
1. Describe the current behavior of this page. What sequence of events occurs when the user clicks on one of the buttons? Be specific. Does the behavior depend on which button was clicked?
2. The span names numSpan is intended to keep track of the number of times the user makes a guess. As is, however, it will not work correctly. The first guess would change the contents of the span from 0 to 01, then 011, then 0111, and so on for subsequent guesses. Explain the cause of this unintended behavior. Modify the code so that the span correctly counts the number of guesses.
3. Under what file names are the images of the two cards stored? Where must the files be stored (on what machine and in what directory)?
4. What is the purpose of the first pair of SCRIPT tags in the HEAD of the HTML document (with src="http://balance3e.com/random.js" )? Would the page load and display the same contents without this line? What its behavior change?
5. Modify the JavaScript code in the HTML document so that the message displayed identifies correct or incorrect guesses. That is, if the user clicked on the "Two of Clubs" button and the random card was the two of clubs, then an alert window should appear with the message 'You guessed twoOfClubs. You were right!' A similar message should appear in an alert window if the user correctly clicked on the "Queen of Hearts" button. However, if the button clicked by the user does not match the randomly selected card, then the message in the alert window should end with 'You were wrong!' You do not need to rewrite the entire document, simply give your modifications with clear instructions as to where to insert/update the code.
6. In addition to keeping track of the total number of guesses we would also like the page to keep track of the number of guesses that were correct. Add a span to the Web page, which will appear below the existing span. The new span should have the label "Number of correct guesses:" and should initially contain zero. For each correct guess made by the user, the contents of the new span should be incremented. Again, you do not need to rewrite the entire document, simply give your modifications with clear instructions as to where to insert/update the code.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
