Advertisement
Guest User

Untitled

a guest
May 1st, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4. <title>
  5. COMSC-100 assignment 9 by Jon Doe
  6. </title>
  7. <script type="text/JavaScript">
  8.  
  9. function calculate( ) {
  10. alert("SFB is contagious");
  11. doTheMath();
  12. };
  13.  
  14. function doTheMath() {
  15. var s = getInputAsText( "myResult1Box" );
  16. if (s.toLowerCase() == "byte".toLowerCase())
  17. {
  18. score = score = 0 // got this one right
  19. myResult1 = "correct"
  20. }
  21. else
  22. {
  23. myResult1 = "WRONG! Yes"
  24.  
  25. }
  26. {
  27. score = score + 1 // got this one right
  28. myResult2 = "correct"
  29. }
  30. else
  31. {
  32. myResult2 = "WRONG! It's Obama"
  33.  
  34. }
  35. {
  36. score = score + 2 // got this one right
  37. myResult3 = "correct"
  38. }
  39. else
  40. {
  41. myResult3 = "WRONG! Earth"
  42.  
  43. }
  44.  
  45. };
  46.  
  47. function getInputAsText( _id ) {
  48. return document.getElementById( _id ).value;
  49. };
  50.  
  51. function getInputAsNumber( _id ) {
  52. return parseFloat( getInputAsText( _id ) );
  53. };
  54.  
  55. function setOutput( _id, _value ) {
  56. document.getElementById( _id ).value = _value;
  57. };
  58.  
  59. function sum() {
  60. var a = getInputAsText( "myAnswer1Box" );
  61. var b = getInputAsText( "myAnswer2Box" );
  62. var c = getInputAsText( "myAnswer3Box" );
  63. setOutput("scoreBox", "Your score is " + score + " out of 3")
  64. };
  65.  
  66. </script>
  67. </head>
  68.  
  69. <body>
  70. Instructions: <br>
  71. Answer the three questions and press go. <br>
  72. Your score will then appear. <br>
  73. <br>
  74. Input values: <br>
  75. 1. Are you a human? <input id="myAnswer1Box" type="text" /> <br />
  76. 2. Who is our president? <input id="myAnswer2Box" type="text" /> <br>
  77. 3. What planet do we live on? <input id="myAnswer3Box" type="text" /> <br />
  78. <input id="gobut" type= "button" value="Go" onclick="javascript:calculate( );"> <br>
  79. Output values: <br>
  80. Result #1: <input type="text" id="myResult1Box" /> <br>
  81. Result #2: <input type="text" id="myResult2Box" /> <br>
  82. Result #3: <input type="text" id="myResult3Box" /> <br>
  83. Final score: <input type="text" id="scoreBox" />
  84. </body>
  85.  
  86. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement