Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.61 KB | None | 0 0
  1. <html><head>
  2. <meta charset="utf-8">
  3. <title>LIS 488: Lab 8</title>
  4. </head>
  5.  
  6. <body>
  7.  
  8. <h1>Part 1: Why is my code broken?</h1>
  9.  
  10. <p>Help!  I wrote this code, but it doesn't work! This part is supposed to figure out if someone is
  11. old enough to drink based on their birth year.  By subtracting their birth year from the current year,
  12. we can get a number that's less than 21, in which case they can't drink; greater than 21, in which
  13. case they can; or equal to 21, in which case they might be able to: we'd have to get more information.
  14. <br>
  15. But my if statment doesn't work!  Help meeeeee~~~!
  16. </p>
  17.  
  18. <script>
  19.  
  20. var birthYear = 1999;
  21. drinkingAge(birthYear);
  22.  
  23. birthYear = 1996;
  24. drinkingAge(birthYear);
  25.  
  26. birthYear = 1949;
  27. drinkingAge(birthYear);
  28.  
  29.  
  30.  
  31. function drinkingAge(bYear){
  32.     var currentYear = 2017;
  33.     document.write("<p align=center>You were born in: " + bYear + ". Therefore, you ");
  34.  
  35.     var age = currentYear - bYear;
  36.  
  37.     if(age = 21){
  38.         document.write ("<strong>might</strong> be old enough to drink.  I'm going to need to see some ID.</p>");
  39.     }
  40.     else if(age < 21){
  41.        document.write("are <strong>not</strong> old enough to drink, sorry!</p>");
  42.     }
  43.     else{
  44.         document.write("are old enough to have a drink. Cheers! (Please drink responsibly)</p>");
  45.     }
  46. }
  47.  
  48. </script>
  49.  
  50. <hr width="50%" align="center">
  51.  
  52. <p>It's just not a good day for me and code.  This while loop is also broken.  
  53. I wanted it to print the numbers between 1 and 10, but it won't work!</p>
  54.  
  55. <script>
  56.  
  57. var i = 0;
  58.  
  59. while(i<10){
  60.    document.write("<p>"+i+"</p>");
  61.     i++;
  62. }
  63.  
  64.  
  65. </script>
  66.  
  67. <hr width="50%" align="center">
  68.  
  69. <p>Now this stupid form won't work either! Programming stinks! (Just kidding! I love you, computers!)
  70. I wanted this to greet the user and give them an random ID number when they click the button, but nothing happens!
  71. </p>
  72.  
  73.  <form>
  74. Name: <input type="text" name="user">
  75. <br>
  76. <br>
  77. <input name="greet" value="Click me!" type=button onClick=makeId(this.form)>
  78. </form>
  79.  
  80. <p id="IDNum">
  81.  
  82.  
  83. </p>
  84.  
  85. <script>
  86.  
  87. function makeID(f){
  88.     var name = f.user.value;
  89.     if (name == ""){
  90.           document.getElementById("IDNum").innerHTML=("Please enter your name");
  91.     }
  92.     else{
  93.        var id=Math.floor((Math.random() * 10) + 1);
  94.        
  95.        //http://www.w3schools.com/js/js_switch.asp
  96.        var house;
  97.        switch(id%4){
  98.         case 0:
  99.             house = "Hufflepuff";
  100.             break;
  101.         case 1:
  102.             house = "Slytherin";
  103.             break;
  104.         case 2:
  105.             house = "Gryffindor";
  106.             break;
  107.         default:
  108.             house = "Ravenclaw (the best house)";
  109.        
  110.        }
  111.        
  112.        document.getElementById("IDNum").innerHTML=(name +", your ID number is " + id +", which puts you in House " + house);
  113.        
  114.     }  
  115. }
  116.  
  117. </script>
  118.  
  119. <p>
  120. Actually, there's quite a bit going on in that last script.  
  121. Write a brief description of what the code is doing when the makeID function is called:
  122.  
  123.  
  124. <!-- your description goes here -->
  125.  
  126. </p>
  127.  
  128.  
  129. <h1>Interlude: a working example</h1>
  130. <p>
  131. The form and code below are from the slides: they show how to get a number from a form, convert it to another number, and then
  132. report back the new number.  In this case, we are converting from human years to dog years.  For the rest of the assignment,
  133. the goal is for you to use this form and script as a template, and modify the names of the variables and IDs so that they
  134. are appropirate for the equation you are being asked to do.
  135. </p>
  136.  
  137.  
  138. <p>
  139. </p><form>
  140. Your age:<br>
  141. <input type="text" id="age">
  142. <input value="Calculate" type="button" onclick="dogYears()">
  143. <p id="dogAge">
  144. </p>
  145. </form>
  146. <p>
  147.  
  148.  
  149. <script>
  150.     function dogYears(){
  151.         var age =     parseFloat(document.getElementById("age").value);
  152.         var da = age/7;
  153.         document.getElementById("dogAge").innerHTML=("You are " + da + " years old in dog years!");
  154.     }
  155. </script>
  156.  
  157.  
  158. </p><hr width="50%" align="center">
  159.  
  160. <h1>Part 2: Is it colder in Europe?</h1>
  161. <!--
  162. 1. In the HTML, make a form that contains the following:
  163. -  a text input named DegF
  164. -  a button input named calc, with the onClick set to “FahToCel”
  165. -  a paragraph with the id “DegC”
  166.  
  167. 2. After the form, create <script> tags and create a function called “FahToCel”.
  168. 3. Create a variable called “fah” that finds the value of the DegF input from the form and converts it to a number.
  169. 4. Convert fah to Celsius using this equation:
  170.   var cel = (fah - 32.0) * 5.0 / 9.0;
  171. 5. Display the value of the cel variable in the paragraph with the DecC id
  172. -->
  173.  
  174.  
  175. <hr width="50%" align="center">
  176.  
  177. <h1>Part 3: Am I taller in Canada??</h1>
  178. <!--
  179. Based on the steps in Part 2, create another form and script combination.
  180. This one should take in a height in inches and convert it to centimeters (cm =
  181. inches * 2.54) -->
  182.  
  183.  
  184. <hr width="50%" align="center">
  185.  
  186. <h1>Part 4: Dealer's choice</h1>
  187.  
  188. <!--
  189. Write your own code! This one can do whatever you want: it can use a form, or just call a function, whatever! A few ideas:
  190. - Ask user for their name and greet them
  191. - Ask for a weight in lbs and convert it to kgs
  192. - Ask the user a question and display something different depending on their answer:
  193.    - Have the user guess a number that you picked, and tell them if they got it right or wrong
  194.    - Ask their favorite color and comment on it (oooh, or change the background of the page to match it! You'll need to do a bit of extra research for that, though)
  195.    - Ask them a question and provide them with different buttons: depending on what button they push, do something different
  196. -->
  197.  
  198.  
  199. </body></html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement