Advertisement
solbek

Untitled

Apr 27th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. OBLIG 8 - INPUT-FELT HVOR DU SKRIVER FØRST BRUSTYPE SÅ POENG, SÅ NÅR DU TTRYKKER LEGG TIL, LEGGES BRUSEN OG POENGENE I EN LISTE/ARREY
  2. <html>
  3. <head>
  4. <script src="Assignment08.js"></script>
  5. <title>Julebrus</title>
  6. <meta charset="utf-8">
  7. </head>
  8. <body>
  9. <h1>Julebrus</h1>
  10.  
  11. <img src="julebrus.png" style="width:652px;height:435px;"
  12. target="_blank">
  13. <br/> <br/>
  14. Brustype: <input id="brustype" />
  15. <br/> <br/>
  16. Poeng: <input id="poeng" onkeypress="enter(event)"/>
  17. <br/> <br/>
  18. <input type="button" value="Legg til brus" onclick="leggTilBrus()" id="knapp"/>
  19. <div id="brusliste"></div>
  20. </body>
  21.  
  22. <style>
  23. h1 {
  24. color: red;
  25. </style>
  26. </html>
  27.  
  28. function brus(brustype,poeng){
  29. this.brustype = brustype;
  30. this.poeng = poeng;
  31. }
  32.  
  33. function leggTilBrus(){
  34. var soda = document.getElementById("brustype").value;
  35. var points = document.getElementById("poeng").value;
  36.  
  37. if(isNaN(points)==false){
  38. var b = new brus(soda,points);
  39.  
  40. document.getElementById("brustype").value = "";
  41. document.getElementById("poeng").value = "";
  42. brusliste.push(b);
  43. visArray();
  44. }
  45.  
  46. else {
  47. alert ("Du skrev ikke et tall");
  48. }
  49. }
  50.  
  51. var brusliste = [];
  52.  
  53. function visArray(){
  54. brusliste.sort(sorter);
  55. brusliste.reverse();
  56. document.getElementById("brusliste").innerHTML ="";
  57.  
  58. for(var i=0;i<brusliste.length;i++){
  59. document.getElementById("brusliste").innerHTML += brusliste[i].brustype +" "+ brusliste[i].poeng + "<br/>";
  60. }
  61. }
  62.  
  63. function enter(event){
  64. if(event.keyCode==13){
  65. leggTilBrus();
  66. }
  67. }
  68.  
  69. function sorter(brus1,brus2){
  70. return brus1.poeng - brus2.poeng;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement