commit 04efff0d15352b7742144d05c65f02170136cda9 Author: h7x4 Date: Wed Jan 29 12:56:06 2020 +0100 init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3a4978b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +#Ignore vscode settings: +.vscode diff --git a/Javascript-oppgåver.pdf b/Javascript-oppgåver.pdf new file mode 100644 index 0000000..47b9e1a Binary files /dev/null and b/Javascript-oppgåver.pdf differ diff --git a/html/tasks/chapter_1/hello_world/Images/html5.svg b/html/tasks/chapter_1/hello_world/Images/html5.svg new file mode 100755 index 0000000..4e8f76c --- /dev/null +++ b/html/tasks/chapter_1/hello_world/Images/html5.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/html/tasks/chapter_1/hello_world/Images/visualStudioCode.svg b/html/tasks/chapter_1/hello_world/Images/visualStudioCode.svg new file mode 100755 index 0000000..686210c --- /dev/null +++ b/html/tasks/chapter_1/hello_world/Images/visualStudioCode.svg @@ -0,0 +1,16 @@ + + + + + + image/svg+xml + + + + + + + + + + diff --git a/html/tasks/chapter_1/hello_world/Karate.ttf b/html/tasks/chapter_1/hello_world/Karate.ttf new file mode 100755 index 0000000..32c61ae Binary files /dev/null and b/html/tasks/chapter_1/hello_world/Karate.ttf differ diff --git a/html/tasks/chapter_1/hello_world/Main.css b/html/tasks/chapter_1/hello_world/Main.css new file mode 100755 index 0000000..1e726b5 --- /dev/null +++ b/html/tasks/chapter_1/hello_world/Main.css @@ -0,0 +1,50 @@ +html { + + +} + +@font-face { + font-family: 'Karate'; + src: url('Karate.ttf') format('truetype'); +} + +body { + margin: 0%; + padding: 0%; + border: 0%; + background-color: rgb(32, 32, 32); +} + +h1 { + color: rgb(0, 255, 13); + text-align: center; + font-size: 5em; + font-family: Karate; +} + + +p, h2, h3, h4, h5 { + color: white; +} + +a { color: rgb(49, 188, 216); } +a:hover { color: rgb(42, 255, 5); } + +.header{ /* This is an example of a class */ + + + +} + +#video{ /* This is an example of an ID */ + + +} + +#linkimage{ + position: fixed; + right: 1em; + bottom: 1em; + width: 10em; + height: 10em; +} \ No newline at end of file diff --git a/html/tasks/chapter_1/hello_world/js/lorem-ipsum.js b/html/tasks/chapter_1/hello_world/js/lorem-ipsum.js new file mode 100755 index 0000000..ea19597 --- /dev/null +++ b/html/tasks/chapter_1/hello_world/js/lorem-ipsum.js @@ -0,0 +1,227 @@ +/** + * @fileOverview Generates "Lorem ipsum" style text. + * @author rviscomi@gmail.com Rick Viscomi, + * tinsley@tinsology.net Mathew Tinsley + * @version 1.0 + */ + +/** + * Copyright (c) 2009, Mathew Tinsley (tinsley@tinsology.net) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the organization nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY MATHEW TINSLEY ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @class Jibborish generator. + */ +var LoremIpsum = function () { +}; + +/** + * Average number of words per sentence. + * @constant {number} + */ +LoremIpsum.WORDS_PER_SENTENCE_AVG = 24.460; + +/** + * Standard deviation of the number of words per sentence. + * @constant {number} + */ +LoremIpsum.WORDS_PER_SENTENCE_STD = 5.080; + +/** + * List of possible words. + * @constant {Array.string} + */ +LoremIpsum.WORDS = [ + 'lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', + 'adipiscing', 'elit', 'curabitur', 'vel', 'hendrerit', 'libero', + 'eleifend', 'blandit', 'nunc', 'ornare', 'odio', 'ut', + 'orci', 'gravida', 'imperdiet', 'nullam', 'purus', 'lacinia', + 'a', 'pretium', 'quis', 'congue', 'praesent', 'sagittis', + 'laoreet', 'auctor', 'mauris', 'non', 'velit', 'eros', + 'dictum', 'proin', 'accumsan', 'sapien', 'nec', 'massa', + 'volutpat', 'venenatis', 'sed', 'eu', 'molestie', 'lacus', + 'quisque', 'porttitor', 'ligula', 'dui', 'mollis', 'tempus', + 'at', 'magna', 'vestibulum', 'turpis', 'ac', 'diam', + 'tincidunt', 'id', 'condimentum', 'enim', 'sodales', 'in', + 'hac', 'habitasse', 'platea', 'dictumst', 'aenean', 'neque', + 'fusce', 'augue', 'leo', 'eget', 'semper', 'mattis', + 'tortor', 'scelerisque', 'nulla', 'interdum', 'tellus', 'malesuada', + 'rhoncus', 'porta', 'sem', 'aliquet', 'et', 'nam', + 'suspendisse', 'potenti', 'vivamus', 'luctus', 'fringilla', 'erat', + 'donec', 'justo', 'vehicula', 'ultricies', 'varius', 'ante', + 'primis', 'faucibus', 'ultrices', 'posuere', 'cubilia', 'curae', + 'etiam', 'cursus', 'aliquam', 'quam', 'dapibus', 'nisl', + 'feugiat', 'egestas', 'class', 'aptent', 'taciti', 'sociosqu', + 'ad', 'litora', 'torquent', 'per', 'conubia', 'nostra', + 'inceptos', 'himenaeos', 'phasellus', 'nibh', 'pulvinar', 'vitae', + 'urna', 'iaculis', 'lobortis', 'nisi', 'viverra', 'arcu', + 'morbi', 'pellentesque', 'metus', 'commodo', 'ut', 'facilisis', + 'felis', 'tristique', 'ullamcorper', 'placerat', 'aenean', 'convallis', + 'sollicitudin', 'integer', 'rutrum', 'duis', 'est', 'etiam', + 'bibendum', 'donec', 'pharetra', 'vulputate', 'maecenas', 'mi', + 'fermentum', 'consequat', 'suscipit', 'aliquam', 'habitant', 'senectus', + 'netus', 'fames', 'quisque', 'euismod', 'curabitur', 'lectus', + 'elementum', 'tempor', 'risus', 'cras' +]; + +/** + * Generate "Lorem ipsum" style words. + * @param num_words {number} Number of words to generate. + * @return {string} "Lorem ipsum..." + */ +LoremIpsum.prototype.generate = function (num_words) { + var words, ii, position, word, current, sentences, sentence_length, sentence; + + /** + * @default 100 + */ + num_words = num_words || 100; + + words = [LoremIpsum.WORDS[0], LoremIpsum.WORDS[1]]; + num_words -= 2; + + for (ii = 0; ii < num_words; ii++) { + position = Math.floor(Math.random() * LoremIpsum.WORDS.length); + word = LoremIpsum.WORDS[position]; + + if (ii > 0 && words[ii - 1] === word) { + ii -= 1; + + } else { + words[ii] = word; + } + } + + sentences = []; + current = 0; + + while (num_words > 0) { + sentence_length = this.getRandomSentenceLength(); + + if (num_words - sentence_length < 4) { + sentence_length = num_words; + } + + num_words -= sentence_length; + + sentence = []; + + for (ii = current; ii < (current + sentence_length); ii++) { + sentence.push(words[ii]); + } + + sentence = this.punctuate(sentence); + current += sentence_length; + sentences.push(sentence.join(' ')); + } + + return sentences.join(' '); +}; + +/** + * Insert commas and periods in the given sentence. + * @param {Array.string} sentence List of words in the sentence. + * @return {Array.string} Sentence with punctuation added. + */ +LoremIpsum.prototype.punctuate = function (sentence) { + var word_length, num_commas, ii, position; + + word_length = sentence.length; + + /* End the sentence with a period. */ + sentence[word_length - 1] += '.'; + + if (word_length < 4) { + return sentence; + } + + num_commas = this.getRandomCommaCount(word_length); + + for (ii = 0; ii <= num_commas; ii++) { + position = Math.round(ii * word_length / (num_commas + 1)); + + if (position < (word_length - 1) && position > 0) { + /* Add the comma. */ + sentence[position] += ','; + } + } + + /* Capitalize the first word in the sentence. */ + sentence[0] = sentence[0].charAt(0).toUpperCase() + sentence[0].slice(1); + + return sentence; +}; + +/** + * Produces a random number of commas. + * @param {number} word_length Number of words in the sentence. + * @return {number} Random number of commas + */ +LoremIpsum.prototype.getRandomCommaCount = function (word_length) { + var base, average, standard_deviation; + + /* Arbitrary. */ + base = 6; + + average = Math.log(word_length) / Math.log(base); + standard_deviation = average / base; + + return Math.round(this.gaussMS(average, standard_deviation)); +}; + +/** + * Produces a random sentence length based on the average word length + * of an English sentence. + * @return {number} Random sentence length + */ +LoremIpsum.prototype.getRandomSentenceLength = function () { + return Math.round( + this.gaussMS( + LoremIpsum.WORDS_PER_SENTENCE_AVG, + LoremIpsum.WORDS_PER_SENTENCE_STD + ) + ); +}; + +/** + * Produces a random number. + * @return {number} Random number + */ +LoremIpsum.prototype.gauss = function () { + return (Math.random() * 2 - 1) + + (Math.random() * 2 - 1) + + (Math.random() * 2 - 1); +}; + +/** + * Produces a random number with Gaussian distribution. + * @param {number} mean + * @param {number} standard_deviation + * @return {number} Random number + */ +LoremIpsum.prototype.gaussMS = function (mean, standard_deviation) { + return Math.round(this.gauss() * standard_deviation + mean); +}; \ No newline at end of file diff --git a/html/tasks/chapter_1/hello_world/oppgave.html b/html/tasks/chapter_1/hello_world/oppgave.html new file mode 100755 index 0000000..ca944e4 --- /dev/null +++ b/html/tasks/chapter_1/hello_world/oppgave.html @@ -0,0 +1,49 @@ + + + + + + + + + + + Hello World! + + + + + +

Header

+

This is an example of a website. Please turn down the volume in order to play the soundcloud track. (Which doesn't exist anymore because I removed it some time ago ¯\_(ツ)_/¯

+
+ + +

Class Header

+

+ Click me! +

+
+ + +

Lorem Ipsum

+

+ +

+ + + + + + + \ No newline at end of file diff --git a/html/tasks/chapter_1/oppgave 2/oppgave.html b/html/tasks/chapter_1/oppgave 2/oppgave.html new file mode 100755 index 0000000..eac2cc3 --- /dev/null +++ b/html/tasks/chapter_1/oppgave 2/oppgave.html @@ -0,0 +1,15 @@ + + + + + + + Oppgave X + + + + + +

Oppgave X

+ + \ No newline at end of file diff --git a/html/tasks/chapter_1/oppgave 2/script.js b/html/tasks/chapter_1/oppgave 2/script.js new file mode 100755 index 0000000..e69de29 diff --git a/html/tasks/chapter_2/clock/oppgave.html b/html/tasks/chapter_2/clock/oppgave.html new file mode 100755 index 0000000..c892f24 --- /dev/null +++ b/html/tasks/chapter_2/clock/oppgave.html @@ -0,0 +1,14 @@ + + + + + + Clock + + +

Clock

+

The clock right now is: Couldn't recieve data.

+ + + + \ No newline at end of file diff --git a/html/tasks/chapter_2/clock/script.js b/html/tasks/chapter_2/clock/script.js new file mode 100755 index 0000000..23cda35 --- /dev/null +++ b/html/tasks/chapter_2/clock/script.js @@ -0,0 +1,15 @@ +window.onload = updateTime; + +function updateTime() { + var time = new Date(); + var timeBox = document.getElementById("pointOfTime"); + var hours = time.getHours(); + var minutes = time.getMinutes(); + var seconds = time.getSeconds(); + + timeBox.innerHTML = hours+":"+minutes+":"+seconds; + +/* setTimeout(updateTime, 1000); */ +} + +setInterval(updateTime, 1000); diff --git a/html/tasks/chapter_3/examples/oppgave.html b/html/tasks/chapter_3/examples/oppgave.html new file mode 100755 index 0000000..33acec8 --- /dev/null +++ b/html/tasks/chapter_3/examples/oppgave.html @@ -0,0 +1,56 @@ + + + + + + + + Document + + + +

Header

+

A paragraph

+ +
+

Button clicks: 0

+ + + + + + + \ No newline at end of file diff --git a/html/tasks/chapter_5/task11_tables/oppgave.html b/html/tasks/chapter_5/task11_tables/oppgave.html new file mode 100644 index 0000000..dad4133 --- /dev/null +++ b/html/tasks/chapter_5/task11_tables/oppgave.html @@ -0,0 +1,30 @@ + + + + + + + Oppgave 11 + + + + + +

Oppgave 11

+ +
+
+ Lag tilfeldige tall mellom 0 og + +
+ + + + + + + +
Tall
+
+ + \ No newline at end of file diff --git a/html/tasks/chapter_5/task11_tables/script.js b/html/tasks/chapter_5/task11_tables/script.js new file mode 100644 index 0000000..e03d4d4 --- /dev/null +++ b/html/tasks/chapter_5/task11_tables/script.js @@ -0,0 +1,34 @@ +const table = document.getElementById("table"); +const globalAmount = document.getElementById("amount"); +const globalRange = document.getElementById("range"); +const reloadButton = document.getElementById("reload"); + +const listHeader = table.innerHTML; + +globalAmount.addEventListener("input", updateList, false); +globalRange.addEventListener("input", updateList, false); +reloadButton.addEventListener("click", updateList, false); + +function updateList() { + addToList(generateNums(globalAmount.value, globalRange.value), table); +} + +function addToList(numArray, table) { + rows = ''; + for (i in numArray) { + rows += '' + numArray[i] + ''; + } + table.innerHTML = listHeader + rows; +} + +function generateNums(amount, range) { + let array = []; + for (i=0; i + + + + + + Rot n + + + + + +

Rot(n)

+ +

Encryption

+
+ Message
+ + Cipher: + + +
+ +

+ +

Decryption

+
+ Message
+ + Cipher: + + +
+ +

+ + + \ No newline at end of file diff --git a/html/tasks/chapter_5/task12_encryption/script.js b/html/tasks/chapter_5/task12_encryption/script.js new file mode 100755 index 0000000..57e1f73 --- /dev/null +++ b/html/tasks/chapter_5/task12_encryption/script.js @@ -0,0 +1,71 @@ +var encForm = document.getElementById("encrypt"); +var emess = document.getElementById("emess"); +var eciph = document.getElementById("enum"); +var etext = document.getElementById("etext"); +encForm.onsubmit=function(evt){ + evt.preventDefault(); + etext.innerHTML = encrypt(emess.value, parseInt(eciph.value)); +} + +var decForm = document.getElementById("decrypt"); +var dmess = document.getElementById("dmess"); +var dciph = document.getElementById("dnum"); +var dtext = document.getElementById("dtext"); +decForm.onsubmit=function(evt){ + evt.preventDefault(); + dtext.innerHTML = decrypt(dmess.value, parseInt(dciph.value)); +} + +function mod(x,n){ + return ((x%n)+n)%n; +} + + +function encrypt(mess,number){ + messArray=mess.split(''); + result=[]; + + for (i in messArray){ + x=messArray[i].charCodeAt(0); + + if (x>64 && x<91){ + x-=64; + x+=number; + x=mod(x,26); + x+=64; + } else if (x>96 && x<123){ + x-=96; + x+=number; + x=mod(x,26); + x+=96; + } + result.push(String.fromCharCode(x)); + } + result = result.join(""); + return result; + +} + +function decrypt(mess,number){ + messArray=mess.split(''); + result=[]; + + for (i in messArray){ + x=messArray[i].charCodeAt(0); + + if (x>64 && x<91){ + x-=64; + x-=number; + x=mod(x,26); + x+=64; + } else if (x>96 && x<123){ + x-=96; + x-=number; + x=mod(x,26); + x+=96; + } + result.push(String.fromCharCode(x)); + } + result = result.join(""); + return result; +} \ No newline at end of file diff --git a/html/tasks/chapter_6/canvas/oppgave.html b/html/tasks/chapter_6/canvas/oppgave.html new file mode 100755 index 0000000..6ee63d0 --- /dev/null +++ b/html/tasks/chapter_6/canvas/oppgave.html @@ -0,0 +1,13 @@ + + + + + + + Canvas Test + + + + + + \ No newline at end of file diff --git a/html/tasks/chapter_6/canvas/script.js b/html/tasks/chapter_6/canvas/script.js new file mode 100755 index 0000000..89a649d --- /dev/null +++ b/html/tasks/chapter_6/canvas/script.js @@ -0,0 +1,64 @@ +var canvas=document.getElementById("canvas"); + +document.getElementsByTagName("body")[0].style.margin="0cm"; +canvas.width = document.documentElement.clientWidth; +canvas.height = document.documentElement.clientHeight; + +const ctx = canvas.getContext("2d"); +let canvasColor = '#000000'; +let rectSize = 20; + + +rect(0,0,33,20); +rect(100,100,120,203); + + +function rect(x, y, length, height) { + ctx.beginPath(); + ctx.rect(x, y, length, height); + ctx.fillRect(x, y, length, height); + ctx.stroke(); +} + +canvas.onclick = function(evt) { + x = evt.clientX; + y = evt.clientY; + rect(x-(rectSize/2), y-(rectSize/2), rectSize, rectSize); +} + +document.getElementsByTagName("body")[0].addEventListener('keydown', changeColor, false); + +function changeColor(evt) { + if (evt.key == "r") { + canvasColor = '#ff0000' + } + if (evt.key == "B") { + canvasColor = '#000000' + } + if (evt.key == "g") { + canvasColor = '#00ff00' + } + if (evt.key == "b") { + canvasColor = '#0000ff' + } + if (evt.key == "y") { + canvasColor = '#ffff00' + } + if (evt.key == "+") { + rectSize+=4; + } + + if (evt.key == "-") { + try { + rectSize-=4; + if (rectSize < 0) throw "rectSize too small" + } catch(err) { + rectSize+=4; + console.error(err); + } + } + + + ctx.strokeStyle = canvasColor; + ctx.fillStyle = canvasColor; +} \ No newline at end of file diff --git a/html/tasks/chapter_6/canvashouse/oppgave.html b/html/tasks/chapter_6/canvashouse/oppgave.html new file mode 100644 index 0000000..c208eb3 --- /dev/null +++ b/html/tasks/chapter_6/canvashouse/oppgave.html @@ -0,0 +1,23 @@ + + + + + + + Canvas House + + + + + +

Canvas House

+ +
+ +
+ +
+ +
+ + \ No newline at end of file diff --git a/html/tasks/chapter_6/canvashouse/script.js b/html/tasks/chapter_6/canvashouse/script.js new file mode 100644 index 0000000..6c536cd --- /dev/null +++ b/html/tasks/chapter_6/canvashouse/script.js @@ -0,0 +1,117 @@ +const houseC = document.getElementById("House"); +const colorC = document.getElementById("color"); +const colorPick = document.getElementById("colorPicker"); + +/*Define dimensions of canvas */ +houseC.width = 480; +houseC.height = 480; +colorC.width = 480; +colorC.height = 480; + +/*Initialize canvas contexts */ +const house = houseC.getContext("2d"); +const color = colorC.getContext("2d"); + +/*Define points for house */ +const housePoints = [ + {x: houseC.width/2, y: houseC.height/3}, + {x: houseC.width/3, y: houseC.height/2}, + {x: houseC.width/3, y: houseC.height/4*3}, + {x: houseC.width/3*2, y: houseC.height/4*3}, + {x: houseC.width/3*2, y: houseC.height/2} +]; + +/*Initialize script */ +clearCanvas(); +drawHouseOutline(); +drawHouse("#ffffff"); +drawColors(); + + +colorC.addEventListener("click", chooseColor, false); + +/*Changes color of the house depending on clicked color on colorCanvas */ +function chooseColor(evt) { + x = evt.clientX + document.body.scrollLeft + document.documentElement.scrollLeft; //BUG: goes from -1 to 479 + y = evt.clientY + document.body.scrollTop + document.documentElement.scrollTop; + + x -= colorC.offsetLeft; + y -=colorC.offsetTop; + + if (((x>colorC.width/5) && (xcolorC.height/5*2) && (ycolorC.width/5*2) && (xcolorC.height/5*2) && (ycolorC.width/5*3) && (xcolorC.height/5*2) && (y + + + + + + Oppgave 10 + + + + + + +

Oppgave 10

+ +
+
+ + + + + +
+ +
+ + +
+ +
+
+ +
+ + \ No newline at end of file diff --git a/html/tasks/chapter_6/task10_localstorage/script.js b/html/tasks/chapter_6/task10_localstorage/script.js new file mode 100755 index 0000000..b522eaf --- /dev/null +++ b/html/tasks/chapter_6/task10_localstorage/script.js @@ -0,0 +1,46 @@ +authorTextBox = document.getElementById("author"); +titleTextBox = document.getElementById("title"); +inputButton = document.getElementById("input"); +sendLocalstorageButton = document.getElementById("send"); +getLocalstorageButton = document.getElementById("get"); +grid = document.getElementsByClassName("textboxGrid")[0] + +inputButton.addEventListener("click", addTextBoxLocal, false); +sendLocalstorageButton.addEventListener("click", sendLocalstorage, false); +getLocalstorageButton.addEventListener("click", getLocalstorage, false); + +function addTextBoxLocal() { + addTextBox(authorTextBox.value, titleTextBox.value); + authorTextBox.value = ""; + titleTextBox.value = ""; +} + +function addTextBox(author, title) { + box = '
'; + box+= '

' + author + '

'; + box += '

' + title + '

'; + box += '
'; + grid.innerHTML += box; +} + +function sendLocalstorage() { + const elements = document.getElementsByClassName("textboxGridElement"); + + // Make array of objects that contain title and author, and send to localstorage + let objectArray = []; + for (i=0; i + + + + + + Kvitter + + + + + + +

Kvitter - Skriv innlegg

+ +
+ +
+ + +

/100

+ +

Captcha

+ +

+ +
+

Du svarte feil. Prøv igjen.


+ Hvilken dag er det i dag?
+

Feil dato. Prøv igjen.

+ + +
+ +
+ + \ No newline at end of file diff --git a/html/tasks/chapter_6/task3_kvitter/script.js b/html/tasks/chapter_6/task3_kvitter/script.js new file mode 100755 index 0000000..70f18f7 --- /dev/null +++ b/html/tasks/chapter_6/task3_kvitter/script.js @@ -0,0 +1,67 @@ +var postData = document.getElementById("postData"); +var postText = document.getElementById("postText"); +var charNum = document.getElementById("charNum"); +var captchaDate = document.getElementById("date"); +var dateError = document.getElementById("dateError"); +var captchaText = document.getElementById("captchaQuestion"); +var captchaAnswer = document.getElementById("captchaAnswer"); +var captchaError = document.getElementById("captchaError"); + +let captchaNum; + +captchaText.onload = generateCaptcha(); + +postData.onsubmit=function(evt){ + evt.preventDefault(); + + if (!checkCaptcha()) { + captchaError.style.visibility = "visible"; + generateCaptcha(); + return false; + } + if (!checkDate()) { + dateError.style.visibility = "visible"; + return false; + } + + clearPost(); + +} + +postText.oninput=function(){ +charNum.innerHTML = postText.value.length; +} + + +function generateCaptcha() { + let Num1 = Math.ceil(Math.random()*5); + let Num2 = Math.ceil(Math.random()*5); + captchaNum = Num1+Num2; + captchaText.innerHTML = (String(Num1) + " + " + String(Num2)); +} + +function checkCaptcha() { + return (captchaAnswer.value == captchaNum) ? true : false; +} + +function checkDate() { + var today = new Date(); + + var month = String(today.getMonth()+1); + if (month.length != 2) { + month = "0" + month; + } + + var date = today.getFullYear() + "-" + month + "-" + today.getDate(); + return (date == captchaDate.value) ? true : false; +} + +function clearPost() { + postText.value = ""; + captchaError.style.visibility = "hidden"; + dateError.style.visibility = "hidden"; + date.value = ""; + captchaAnswer.value = ""; + charNum.innerHTML = "0"; + generateCaptcha(); +} \ No newline at end of file diff --git a/html/tasks/extra/task1/oppgave.html b/html/tasks/extra/task1/oppgave.html new file mode 100644 index 0000000..51f0670 --- /dev/null +++ b/html/tasks/extra/task1/oppgave.html @@ -0,0 +1,13 @@ + + + + + + + Almost Increasing Sequence + + + + Se i terminalen. + + \ No newline at end of file diff --git a/html/tasks/extra/task1/script.js b/html/tasks/extra/task1/script.js new file mode 100644 index 0000000..38d225f --- /dev/null +++ b/html/tasks/extra/task1/script.js @@ -0,0 +1,24 @@ +/* +Om vi ser på tallene som trappetrinn, kan vi omdefinere problemet til at tallene +ikke må trappe ned to ganger i løpet av rekken. Enten må vi ta vekk det ene nedtrappet +eller så må vi ta vekk det andre, men vi står fortsatt alltid igjen med ett av dem. +*/ + +function almostIncreasingSequence(sequence) { + let decreaseCounter=0; + for (elements in sequence){ + if (sequence[elements] > sequence[parseInt(elements)+1]) { + decreaseCounter++; + if (decreaseCounter > 1) { + return false; + } + } + } + return true; +} + +/* Test */ +console.log("[1,3,2,1]" + " -> " + almostIncreasingSequence([1,3,2,1])); +console.log("[1,3,2]" + " -> " + almostIncreasingSequence([1,3,2])); +console.log("[1,3,2,4,5,6,8]" + " -> " + almostIncreasingSequence([1,3,2,4,5,6,8])); +console.log("[1,3,2,4,5,6,8,2]" + " -> " + almostIncreasingSequence([1,3,2,4,5,6,8,2])); \ No newline at end of file diff --git a/html/tasks/template/OppgaveMal/oppgave.html b/html/tasks/template/OppgaveMal/oppgave.html new file mode 100755 index 0000000..eac2cc3 --- /dev/null +++ b/html/tasks/template/OppgaveMal/oppgave.html @@ -0,0 +1,15 @@ + + + + + + + Oppgave X + + + + + +

Oppgave X

+ + \ No newline at end of file diff --git a/html/tasks/template/OppgaveMal/script.js b/html/tasks/template/OppgaveMal/script.js new file mode 100755 index 0000000..e69de29 diff --git a/html/test_15.11.19/IT2 heildagsprøve 15. nov. 2019 småoppgåver.pdf b/html/test_15.11.19/IT2 heildagsprøve 15. nov. 2019 småoppgåver.pdf new file mode 100755 index 0000000..6414ee7 Binary files /dev/null and b/html/test_15.11.19/IT2 heildagsprøve 15. nov. 2019 småoppgåver.pdf differ diff --git a/html/test_15.11.19/html/task1.html b/html/test_15.11.19/html/task1.html new file mode 100755 index 0000000..e51dc63 --- /dev/null +++ b/html/test_15.11.19/html/task1.html @@ -0,0 +1,18 @@ + + + + + + + Oppgave 1 + + + +

Oppgave 1

+ + + +

Sjekk terminalen

+ + + \ No newline at end of file diff --git a/html/test_15.11.19/html/task2.html b/html/test_15.11.19/html/task2.html new file mode 100755 index 0000000..68a8918 --- /dev/null +++ b/html/test_15.11.19/html/task2.html @@ -0,0 +1,18 @@ + + + + + + + Oppgave 2 + + + +

Oppgave 2

+ + + +

Sjekk terminalen

+ + + \ No newline at end of file diff --git a/html/test_15.11.19/html/task3.html b/html/test_15.11.19/html/task3.html new file mode 100755 index 0000000..23ac93e --- /dev/null +++ b/html/test_15.11.19/html/task3.html @@ -0,0 +1,18 @@ + + + + + + + Oppgave 3 + + + +

Oppgave 3

+ + + +

Sjekk terminalen

+ + + \ No newline at end of file diff --git a/html/test_15.11.19/html/task4.html b/html/test_15.11.19/html/task4.html new file mode 100755 index 0000000..45877d9 --- /dev/null +++ b/html/test_15.11.19/html/task4.html @@ -0,0 +1,18 @@ + + + + + + + Oppgave 4 + + + +

Oppgave 4

+ + + +

Sjekk terminalen

+ + + \ No newline at end of file diff --git a/html/test_15.11.19/html/task5.html b/html/test_15.11.19/html/task5.html new file mode 100755 index 0000000..daaea7a --- /dev/null +++ b/html/test_15.11.19/html/task5.html @@ -0,0 +1,21 @@ + + + + + + + Oppgave 5 + + + +

Oppgave 5

+ +

Alder: år

+

Standard pris: kr

+

Rabatt: %

+

Sluttpris: kr

+ + + + + \ No newline at end of file diff --git a/html/test_15.11.19/html/task6.html b/html/test_15.11.19/html/task6.html new file mode 100755 index 0000000..7510394 --- /dev/null +++ b/html/test_15.11.19/html/task6.html @@ -0,0 +1,21 @@ + + + + + + + Oppgave 6 + 6C + + + +

Oppgave 6 + 6C

+ +

Spørsmål

+

+ + + + + + + \ No newline at end of file diff --git a/html/test_15.11.19/html/task7.html b/html/test_15.11.19/html/task7.html new file mode 100755 index 0000000..5c7fb38 --- /dev/null +++ b/html/test_15.11.19/html/task7.html @@ -0,0 +1,22 @@ + + + + + + + Oppgave 7 + + + +

Oppgave 7

+ +

Antall 6ere:

+

Antall tall over 50:

+

Prosent tall over 50: %

+ + + + + + + \ No newline at end of file diff --git a/html/test_15.11.19/index.html b/html/test_15.11.19/index.html new file mode 100755 index 0000000..e97c29e --- /dev/null +++ b/html/test_15.11.19/index.html @@ -0,0 +1,31 @@ + + + + + + + Prøve 15.11.19 + + + + +

Prøve 15.11.2019

+ + Oppgave 1 +
+ Oppgave 2 +
+ Oppgave 3 +
+ Oppgave 4 +
+ Oppgave 5 +
+ Oppgave 6 +
+ Oppgave 7 + + + + + \ No newline at end of file diff --git a/html/test_15.11.19/javascript/task1.js b/html/test_15.11.19/javascript/task1.js new file mode 100755 index 0000000..768af59 --- /dev/null +++ b/html/test_15.11.19/javascript/task1.js @@ -0,0 +1,4 @@ +const num1 = 5; +const num2 = 10; + +console.log(num1 + " ganger " + num2 + " er " + (num1 * num2)); \ No newline at end of file diff --git a/html/test_15.11.19/javascript/task2.js b/html/test_15.11.19/javascript/task2.js new file mode 100755 index 0000000..2b98864 --- /dev/null +++ b/html/test_15.11.19/javascript/task2.js @@ -0,0 +1,14 @@ +/*Input from user and convert to lower case*/ +const firstName = prompt("Hva er fornavnet ditt?").toLowerCase(); +const surname = prompt("Hva er etternavnet ditt?").toLowerCase(); +const domain = prompt("Skriv inn et domenenavn", "eksempel.no").toLowerCase(); + + +/*Combine the input and print it out*/ +const email = firstName + "." + surname + "@" + domain; +console.log("Email: " + email); + +/*Combine and add a random number between 1 and 100 with a little bit lower probability for 1 and 100*/ +const mailNum = parseInt((Math.random() *100) +1); +const altEmail = firstName + "." + surname + mailNum + "@" + domain; +console.log ("Alternativ Email: " + altEmail); \ No newline at end of file diff --git a/html/test_15.11.19/javascript/task3.js b/html/test_15.11.19/javascript/task3.js new file mode 100755 index 0000000..58f96d2 --- /dev/null +++ b/html/test_15.11.19/javascript/task3.js @@ -0,0 +1,14 @@ +//Oppgave a +console.log("a)"); + +var gate = "Kongens gate"; +var husnr = 432; +var oppgang = "b"; //added quotation marks +var adresse = gate + husnr + oppgang; +console.log(adresse); //added semicolon + +//Oppgave b +console.log("b)"); + +console.log("Adressen er " + gate + " " + husnr + oppgang); +console.log("Gaten er " + gate + ", husnummeret er " + husnr + ", oppgang " + oppgang); \ No newline at end of file diff --git a/html/test_15.11.19/javascript/task4.js b/html/test_15.11.19/javascript/task4.js new file mode 100755 index 0000000..8a15238 --- /dev/null +++ b/html/test_15.11.19/javascript/task4.js @@ -0,0 +1,18 @@ +//Oppgave a +const priceSum = 857; +const discountNum = 0.25; +const tipNum = 0.1; + +//Oppgave b + +/*Jeg antar at tipsen blir regnet ut før rabatten er påført*/ + +let totalPrice = (priceSum - (discountNum*priceSum) + (tipNum*priceSum)); + +//Oppgave c + +const personNum = 5; +const pricePerPerson = (totalPrice/personNum).toFixed(2); + +console.log("Antall personer: " + personNum); +console.log("Pris per person: " + pricePerPerson + "kr"); \ No newline at end of file diff --git a/html/test_15.11.19/javascript/task5.js b/html/test_15.11.19/javascript/task5.js new file mode 100755 index 0000000..a9a31cb --- /dev/null +++ b/html/test_15.11.19/javascript/task5.js @@ -0,0 +1,47 @@ +/*Input and variables */ +const routePrice = [150, 250, 50]; +const ageDiscount = [0.0, 0.5, 1.0, 0.3]; + +let route = prompt("Hvilken reisestrekning skal du reise? Skriv inn et tall \n 1 = By-Sjø \n 2 = Sjø-Fjell \n 3 = Fjell-By", "1"); + +let pris = 0; +let totalsum = 0; + +let age = parseInt(prompt("Hvor mange år er du?")); + +/*Jeg antar at 0-2 betyr fra og med 0 til (ikke med) 2 */ + +/*Process what discount should be chosen based on age */ +if ( age >= 0 && age < 2) { + discountNum = 0; +} else if (age < 16) { + discountNum = 1; +} else if (age < 65) { + discountNum = 2; +} else if (age >= 65) { + discountNum = 3; +} + +/*I dette punktet i pseudokoden står det at +* den rabatterte prisen ut ifra alder og rute +* skal stå i variabel "pris", men jeg går ut +* ifra at "pris" er ment som standard pris og at +* "totalsum" er den rabatterte prisen. +*/ + +pris = routePrice[route]; +totalsum = routePrice[route]*ageDiscount[discountNum]; + + +/*Output */ +let ageBox = document.getElementById("age"); +ageBox.innerHTML = age; + +let standardPriceBox = document.getElementById("standardPrice"); +standardPriceBox.innerHTML = pris; + +let discountBox = document.getElementById("discount"); +discountBox.innerHTML = (1.0-ageDiscount[discountNum])*100; + +let endPriceBox = document.getElementById("endPrice"); +endPriceBox.innerHTML = totalsum; \ No newline at end of file diff --git a/html/test_15.11.19/javascript/task6.js b/html/test_15.11.19/javascript/task6.js new file mode 100755 index 0000000..39b2394 --- /dev/null +++ b/html/test_15.11.19/javascript/task6.js @@ -0,0 +1,25 @@ +const questions = [ + "Hvor mange centimeter er det i en meter", //Dette spørsmålet mangler spørsmålstegn med vilje + "Hvor mange mennesker bor det i verden?", + "Hvilke toner finnes i en C-dur skala?", + "Hvem har verdensrekorden i 100-meter løping?" +]; + +/*Set a random question from "questions[]" into "questionbox" */ +let questionBox = document.getElementById("question"); +let randomNum = Math.floor((Math.random()*questions.length)); +questionBox.innerHTML = questions[randomNum]; + +/*Check for question marks in the current question (no need to search at the last character as this is a one sentence question) */ +if (!(questions[randomNum].includes("?"))){ + questionBox.style = "color: red"; + questionBox.innerHTML = "Spørsmålet kan ikke bli vist frem ettersom det mangler spørsmålstegn. Kontakt administrator."; +} + +/*Button function */ +function refresh(){ + window.location.assign(window.location.hostname); // Kilde: https://www.w3schools.com/js/js_window_location.asp +} + +let refreshBut = document.getElementById("refreshButton"); +refreshBut.onclick = refresh; \ No newline at end of file diff --git a/html/test_15.11.19/javascript/task7.js b/html/test_15.11.19/javascript/task7.js new file mode 100755 index 0000000..3cb6492 --- /dev/null +++ b/html/test_15.11.19/javascript/task7.js @@ -0,0 +1,24 @@ +/*Initialize variables */ +let numbers = [0]; +let statement1Counter = 0; +let statement2Counter = 0; + +/*Add numbers to the array and check if the number is 6 or equal to/bigger than 50 */ +for(i=0; i<1000; i++) { + numbers[i] = Math.floor(Math.random()*101); + if (numbers[i] == 6) { + statement1Counter++; + } else if (numbers[i] >= 50) { + statement2Counter++; + } +} + +/*Output */ +const statement1Box = document.getElementById("6s"); +statement1Box.innerHTML = statement1Counter; + +const statement2Box = document.getElementById("biggerThan50Amount"); +statement2Box.innerHTML = statement2Counter; + +const statement2Box2 = document.getElementById("biggerThan50Percent"); +statement2Box2.innerHTML = ((statement2Counter/numbers.length)*100); \ No newline at end of file diff --git a/html/test_15.11.19/style.css b/html/test_15.11.19/style.css new file mode 100755 index 0000000..933acaf --- /dev/null +++ b/html/test_15.11.19/style.css @@ -0,0 +1,18 @@ +h1{ + color: rgb(130, 130, 255); + text-align: center; +} + +h3{ + color: rgb(140, 255, 130); +} + +body{ + background-color: rgb(36, 36, 36); + margin-left: 10%; + color: white; +} + +a{ + color: turquoise; +} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100755 index 0000000..181407b --- /dev/null +++ b/index.html @@ -0,0 +1,53 @@ + + + + + + + + + + + + Indeks IT2 + + + + + +

Indeks IT2

+ + + + + + diff --git a/resources/css/main.css b/resources/css/main.css new file mode 100755 index 0000000..62a5d4e --- /dev/null +++ b/resources/css/main.css @@ -0,0 +1,123 @@ +body { + + --blue: rgb(40, 131, 208); + --green: rgb(145, 226, 44); + --red: rgb(249, 38, 119); + --yellow: rgb(253, 151, 31); + --purple: rgb(174, 129, 255); + + --grey1: rgb(40, 40, 40); + --grey2: rgb(60, 60, 60); + --grey3: rgb(80, 80, 80); + --grey4: rgb(120, 120, 120); + + --border-color: white; + + --radius: 15px; + --standardMargin: 15px; + + background-color: var(--grey1); + color: white; + + margin: 0px; + padding: 0px; + + margin-right: 2%; + margin-left: 8%; + margin-top: 5%; + + font-family: museo-sans-rounded, sans-serif; + font-weight: 300; + font-style: normal; + +} + +button { + background-color: var(--grey4); + padding: 15px; + display: inline-block; + border: 2px solid var(--border-color); + border-radius: var(--radius); + color: white; + font-size: 16pt; +} +button:hover {background-color: var(--grey3);} +button:focus {outline:0;} + +h1 { + color: var(--blue); + text-align: center; + background-color: var(--grey2); + padding: 15px; + margin-left: 10%; + margin-right: 10%; + border-radius: var(--radius); +} + +h2 { + color: var(--green); +} + +a { color: #66D9EF; } +a:hover { color: #A6E22E; } + +form { + +} + +input[type=text] { + +} + +input[type=color] { + width: 4em; + height: 2em; + background-color: var(--grey4); +} + +.center { + background-color: var(--grey3); + margin: auto; + margin-bottom: 10%; + width: 70%; + padding: 5%; + height: max-content; + border-radius: var(--radius); +} + +.center * { + margin: auto; + display: block; +} + +.inline { + margin: var(--standardMargin); +} + +.inline * { + display: inline-block; +} + +.leftalign * { + margin: var(--standardMargin); + text-align: left; +} + + +table { + width: 100%; +} + +td, th { + border: 1px solid var(--border-color); + padding: 8px; +} + +tr:nth-child(even) { background-color: #00000033} + +tr:hover { background-color: rgba(255, 255, 255, 0.281);} + +th { + text-align: left; + background-color: #4CAF50; +} \ No newline at end of file diff --git a/resources/css/topbar.css b/resources/css/topbar.css new file mode 100755 index 0000000..e69de29