Advertisement
Guest User

Ex 1 Frontend

a guest
Apr 29th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 0.81 KB | None | 0 0
  1. /* We're building a web game where everybody wins and we are all friends forever.
  2. It's simple—you click on one of three boxes to see what nice thing you've won. You always win something nice. Because we love you.
  3. Here's what we have so far. Something's going wrong though. Can you tell what it is? */
  4.  
  5. <button id="btn-0">Button 1!</button>
  6. <button id="btn-1">Button 2!</button>
  7. <button id="btn-2">Button 3!</button>
  8.  
  9. <script type="text/javascript">
  10.     var prizes = ['A Unicorn!', 'A Hug!', 'Fresh Laundry!'];
  11.     for (var btnNum = 0; btnNum < prizes.length; btnNum++) {
  12.        // for each of our buttons, when the user clicks it...
  13.        document.getElementById('btn-' + btnNum).onclick = function() {
  14.            // tell her what she's won!
  15.            alert(prizes[btnNum]);
  16.        };
  17.    }
  18. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement