Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- <html>
- <head>
- <script src="Assignment08.js"></script>
- <title>Julebrus</title>
- <meta charset="utf-8">
- </head>
- <body>
- <h1>Julebrus</h1>
- <img src="julebrus.png" style="width:652px;height:435px;"
- target="_blank">
- <br/> <br/>
- Brustype: <input id="brustype" />
- <br/> <br/>
- Poeng: <input id="poeng" onkeypress="enter(event)"/>
- <br/> <br/>
- <input type="button" value="Legg til brus" onclick="leggTilBrus()" id="knapp"/>
- <div id="brusliste"></div>
- </body>
- <style>
- h1 {
- color: red;
- </style>
- </html>
- function brus(brustype,poeng){
- this.brustype = brustype;
- this.poeng = poeng;
- }
- function leggTilBrus(){
- var soda = document.getElementById("brustype").value;
- var points = document.getElementById("poeng").value;
- if(isNaN(points)==false){
- var b = new brus(soda,points);
- document.getElementById("brustype").value = "";
- document.getElementById("poeng").value = "";
- brusliste.push(b);
- visArray();
- }
- else {
- alert ("Du skrev ikke et tall");
- }
- }
- var brusliste = [];
- function visArray(){
- brusliste.sort(sorter);
- brusliste.reverse();
- document.getElementById("brusliste").innerHTML ="";
- for(var i=0;i<brusliste.length;i++){
- document.getElementById("brusliste").innerHTML += brusliste[i].brustype +" "+ brusliste[i].poeng + "<br/>";
- }
- }
- function enter(event){
- if(event.keyCode==13){
- leggTilBrus();
- }
- }
- function sorter(brus1,brus2){
- return brus1.poeng - brus2.poeng;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement