teamoppgave

This commit is contained in:
Geir Okkenhaug Jerstad 2024-08-30 10:34:25 +02:00
parent 3f49a7433b
commit 7d03b87ddc
5 changed files with 331 additions and 127 deletions

35
MVC/box.html Normal file
View file

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MVC Skjemaer</title>
</head>
<body>
<div id="app">
</div>
<script>
// model
let message = null;// = 'Alt gikk bra';
// view
updateView()
function updateView(){
if (message == null){
} else {
document.getElementById('app').innerHTML = /*HTML*/ `
<h1>Min app</h1>
${message}
<button>Vis sukksess</button>
<button>Vis advarsel</button>
<button></button>
<button>1</button>
`;
};
}
// controller
</script>
</body>
</html>

37
MVC/meldingsbokser.html Normal file
View file

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app">
</div>
<script>
// Model
let number = 5;
let aName;
// view
updateView()
function updateView() {
// let extraWord = '';
// if (number < 10){
// extraWord = 'ikke';
// } else {
// extraWord = '';
// }
document.getElementById('app').innerHTML = /*HTML*/ `
<h1>${number}</h1>
Tallet er ${number <= 10 ? 'ikke' : ''} over 10
<p>Hei ${aName ?? 'på deg!'}</p>
`;
}
</script>
</body>
</html>

View file

@ -1,35 +1,109 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MVC Skjemaer</title> <title>Document</title>
</head> </head>
<body> <body>
<div id="app"> <div id="app">
</div> </div>
<script> <script>
// model // Model
let message = null;// = 'Alt gikk bra'; let aName;
let number;
let fontFamily;
let fontSize;
let isDarkMode = false;
// view // view
updateView() updateView()
function updateView(){ function updateView() {
if (message == null){ // let extraWord = '';
// if (number < 10){
} else { // extraWord = 'ikke';
document.getElementById('app').innerHTML = /*HTML*/ ` // } else {
<h1>Min app</h1> // extraWord = '';
${message} // }
<button>Vis sukksess</button> document.getElementById('app').innerHTML = /*HTML*/ `
<button>Vis advarsel</button> <p>Hei ${aName ?? 'på deg!'}</p>
<button></button> Navn:<br>
<button>1</button> <input
type="text"
oninput="aName=this.value"
value="${aName ?? ''}"/>
Tall:<br>
<input
type="range"
min="1"
max="100"
step="1"
oninput="number=this.valueAsNumber"
value ="${number ?? ''}">${number ?? ''}
<br>
<input
type="checkbox"
oninput="isDarkMode=this.checked"
${isDarkMode ? 'checked' : ''}
>
Dark Mode:
<br>
<button onclick="selectFont('helvetica')">Font A</button>
<button onclick="selectFont('courier')">Font B</button>
<br>
<button
onclick="register()">Registrer</button><br>
<b>Font-størrelse</b><br>
Normal
<input
type="radio"
name="fontSize"
oninput="fontSize='100%'"
${fontSize == '100%' ? 'checked' : ''}
/><br>
50%
<input
type="radio"
name="fontSize"
oninput="fontSize='50%'"
${fontSize == '50%' ? 'checked' : ''}
/> <br>
200%
<input
type="radio"
name="fontSize"
oninput="fontSize='200%'"
${fontSize == '200%' ? 'checked' : ''}
><br>
`; `;
let bodyStyle = document.body.style;
bodyStyle.fontFamily = fontFamily ?? serif;
if (isDarkMode){
bodyStyle.background = 'black';
bodyStyle.color = 'white';
} else {
bodyStyle.background = 'white';
bodyStyle.color = 'black';
}; };
bodyStyle.fontSize = fontSize;
}
// Controller
function register() {
updateView();
}
function selectFont(newFontFamily){
fontFamily = newFontFamily;
updateView()
} }
// controller
</script> </script>
</body> </body>
</html> </html>

View file

@ -1,123 +1,123 @@
// Weresquirrel // Weresquirrel
var JOURNAL = [ var JOURNAL = [
{"events":["carrot","exercise","weekend"],"squirrel":false}, { "events": ["carrot", "exercise", "weekend"], "squirrel": false },
{"events":["bread","pudding","brushed teeth","weekend","touched tree"],"squirrel":false}, { "events": ["bread", "pudding", "brushed teeth", "weekend", "touched tree"], "squirrel": false },
{"events":["carrot","nachos","brushed teeth","cycling","weekend"],"squirrel":false}, { "events": ["carrot", "nachos", "brushed teeth", "cycling", "weekend"], "squirrel": false },
{"events":["brussel sprouts","ice cream","brushed teeth","computer","weekend"],"squirrel":false}, { "events": ["brussel sprouts", "ice cream", "brushed teeth", "computer", "weekend"], "squirrel": false },
{"events":["potatoes","candy","brushed teeth","exercise","weekend","dentist"],"squirrel":false}, { "events": ["potatoes", "candy", "brushed teeth", "exercise", "weekend", "dentist"], "squirrel": false },
{"events":["brussel sprouts","pudding","brushed teeth","running","weekend"],"squirrel":false}, { "events": ["brussel sprouts", "pudding", "brushed teeth", "running", "weekend"], "squirrel": false },
{"events":["pizza","brushed teeth","computer","work","touched tree"],"squirrel":false}, { "events": ["pizza", "brushed teeth", "computer", "work", "touched tree"], "squirrel": false },
{"events":["bread","beer","brushed teeth","cycling","work"],"squirrel":false}, { "events": ["bread", "beer", "brushed teeth", "cycling", "work"], "squirrel": false },
{"events":["cauliflower","brushed teeth","work"],"squirrel":false}, { "events": ["cauliflower", "brushed teeth", "work"], "squirrel": false },
{"events":["pizza","brushed teeth","cycling","work"],"squirrel":false}, { "events": ["pizza", "brushed teeth", "cycling", "work"], "squirrel": false },
{"events":["lasagna","nachos","brushed teeth","work"],"squirrel":false}, { "events": ["lasagna", "nachos", "brushed teeth", "work"], "squirrel": false },
{"events":["brushed teeth","weekend","touched tree"],"squirrel":false}, { "events": ["brushed teeth", "weekend", "touched tree"], "squirrel": false },
{"events":["lettuce","brushed teeth","television","weekend"],"squirrel":false}, { "events": ["lettuce", "brushed teeth", "television", "weekend"], "squirrel": false },
{"events":["spaghetti","brushed teeth","work"],"squirrel":false}, { "events": ["spaghetti", "brushed teeth", "work"], "squirrel": false },
{"events":["brushed teeth","computer","work"],"squirrel":false}, { "events": ["brushed teeth", "computer", "work"], "squirrel": false },
{"events":["lettuce","nachos","brushed teeth","work"],"squirrel":false}, { "events": ["lettuce", "nachos", "brushed teeth", "work"], "squirrel": false },
{"events":["carrot","brushed teeth","running","work"],"squirrel":false}, { "events": ["carrot", "brushed teeth", "running", "work"], "squirrel": false },
{"events":["brushed teeth","work"],"squirrel":false}, { "events": ["brushed teeth", "work"], "squirrel": false },
{"events":["cauliflower","reading","weekend"],"squirrel":false}, { "events": ["cauliflower", "reading", "weekend"], "squirrel": false },
{"events":["bread","brushed teeth","weekend"],"squirrel":false}, { "events": ["bread", "brushed teeth", "weekend"], "squirrel": false },
{"events":["lasagna","brushed teeth","exercise","work"],"squirrel":false}, { "events": ["lasagna", "brushed teeth", "exercise", "work"], "squirrel": false },
{"events":["spaghetti","brushed teeth","reading","work"],"squirrel":false}, { "events": ["spaghetti", "brushed teeth", "reading", "work"], "squirrel": false },
{"events":["carrot","ice cream","brushed teeth","television","work"],"squirrel":false}, { "events": ["carrot", "ice cream", "brushed teeth", "television", "work"], "squirrel": false },
{"events":["spaghetti","nachos","work"],"squirrel":false}, { "events": ["spaghetti", "nachos", "work"], "squirrel": false },
{"events":["cauliflower","ice cream","brushed teeth","cycling","work"],"squirrel":false}, { "events": ["cauliflower", "ice cream", "brushed teeth", "cycling", "work"], "squirrel": false },
{"events":["spaghetti","peanuts","computer","weekend"],"squirrel":true}, { "events": ["spaghetti", "peanuts", "computer", "weekend"], "squirrel": true },
{"events":["potatoes","ice cream","brushed teeth","computer","weekend"],"squirrel":false}, { "events": ["potatoes", "ice cream", "brushed teeth", "computer", "weekend"], "squirrel": false },
{"events":["potatoes","ice cream","brushed teeth","work"],"squirrel":false}, { "events": ["potatoes", "ice cream", "brushed teeth", "work"], "squirrel": false },
{"events":["peanuts","brushed teeth","running","work"],"squirrel":false}, { "events": ["peanuts", "brushed teeth", "running", "work"], "squirrel": false },
{"events":["potatoes","exercise","work"],"squirrel":false}, { "events": ["potatoes", "exercise", "work"], "squirrel": false },
{"events":["pizza","ice cream","computer","work"],"squirrel":false}, { "events": ["pizza", "ice cream", "computer", "work"], "squirrel": false },
{"events":["lasagna","ice cream","work"],"squirrel":false}, { "events": ["lasagna", "ice cream", "work"], "squirrel": false },
{"events":["cauliflower","candy","reading","weekend"],"squirrel":false}, { "events": ["cauliflower", "candy", "reading", "weekend"], "squirrel": false },
{"events":["lasagna","nachos","brushed teeth","running","weekend"],"squirrel":false}, { "events": ["lasagna", "nachos", "brushed teeth", "running", "weekend"], "squirrel": false },
{"events":["potatoes","brushed teeth","work"],"squirrel":false}, { "events": ["potatoes", "brushed teeth", "work"], "squirrel": false },
{"events":["carrot","work"],"squirrel":false}, { "events": ["carrot", "work"], "squirrel": false },
{"events":["pizza","beer","work","dentist"],"squirrel":false}, { "events": ["pizza", "beer", "work", "dentist"], "squirrel": false },
{"events":["lasagna","pudding","cycling","work"],"squirrel":false}, { "events": ["lasagna", "pudding", "cycling", "work"], "squirrel": false },
{"events":["spaghetti","brushed teeth","reading","work"],"squirrel":false}, { "events": ["spaghetti", "brushed teeth", "reading", "work"], "squirrel": false },
{"events":["spaghetti","pudding","television","weekend"],"squirrel":false}, { "events": ["spaghetti", "pudding", "television", "weekend"], "squirrel": false },
{"events":["bread","brushed teeth","exercise","weekend"],"squirrel":false}, { "events": ["bread", "brushed teeth", "exercise", "weekend"], "squirrel": false },
{"events":["lasagna","peanuts","work"],"squirrel":true}, { "events": ["lasagna", "peanuts", "work"], "squirrel": true },
{"events":["pizza","work"],"squirrel":false}, { "events": ["pizza", "work"], "squirrel": false },
{"events":["potatoes","exercise","work"],"squirrel":false}, { "events": ["potatoes", "exercise", "work"], "squirrel": false },
{"events":["brushed teeth","exercise","work"],"squirrel":false}, { "events": ["brushed teeth", "exercise", "work"], "squirrel": false },
{"events":["spaghetti","brushed teeth","television","work"],"squirrel":false}, { "events": ["spaghetti", "brushed teeth", "television", "work"], "squirrel": false },
{"events":["pizza","cycling","weekend"],"squirrel":false}, { "events": ["pizza", "cycling", "weekend"], "squirrel": false },
{"events":["carrot","brushed teeth","weekend"],"squirrel":false}, { "events": ["carrot", "brushed teeth", "weekend"], "squirrel": false },
{"events":["carrot","beer","brushed teeth","work"],"squirrel":false}, { "events": ["carrot", "beer", "brushed teeth", "work"], "squirrel": false },
{"events":["pizza","peanuts","candy","work"],"squirrel":true}, { "events": ["pizza", "peanuts", "candy", "work"], "squirrel": true },
{"events":["carrot","peanuts","brushed teeth","reading","work"],"squirrel":false}, { "events": ["carrot", "peanuts", "brushed teeth", "reading", "work"], "squirrel": false },
{"events":["potatoes","peanuts","brushed teeth","work"],"squirrel":false}, { "events": ["potatoes", "peanuts", "brushed teeth", "work"], "squirrel": false },
{"events":["carrot","nachos","brushed teeth","exercise","work"],"squirrel":false}, { "events": ["carrot", "nachos", "brushed teeth", "exercise", "work"], "squirrel": false },
{"events":["pizza","peanuts","brushed teeth","television","weekend"],"squirrel":false}, { "events": ["pizza", "peanuts", "brushed teeth", "television", "weekend"], "squirrel": false },
{"events":["lasagna","brushed teeth","cycling","weekend"],"squirrel":false}, { "events": ["lasagna", "brushed teeth", "cycling", "weekend"], "squirrel": false },
{"events":["cauliflower","peanuts","brushed teeth","computer","work","touched tree"],"squirrel":false}, { "events": ["cauliflower", "peanuts", "brushed teeth", "computer", "work", "touched tree"], "squirrel": false },
{"events":["lettuce","brushed teeth","television","work"],"squirrel":false}, { "events": ["lettuce", "brushed teeth", "television", "work"], "squirrel": false },
{"events":["potatoes","brushed teeth","computer","work"],"squirrel":false}, { "events": ["potatoes", "brushed teeth", "computer", "work"], "squirrel": false },
{"events":["bread","candy","work"],"squirrel":false}, { "events": ["bread", "candy", "work"], "squirrel": false },
{"events":["potatoes","nachos","work"],"squirrel":false}, { "events": ["potatoes", "nachos", "work"], "squirrel": false },
{"events":["carrot","pudding","brushed teeth","weekend"],"squirrel":false}, { "events": ["carrot", "pudding", "brushed teeth", "weekend"], "squirrel": false },
{"events":["carrot","brushed teeth","exercise","weekend","touched tree"],"squirrel":false}, { "events": ["carrot", "brushed teeth", "exercise", "weekend", "touched tree"], "squirrel": false },
{"events":["brussel sprouts","running","work"],"squirrel":false}, { "events": ["brussel sprouts", "running", "work"], "squirrel": false },
{"events":["brushed teeth","work"],"squirrel":false}, { "events": ["brushed teeth", "work"], "squirrel": false },
{"events":["lettuce","brushed teeth","running","work"],"squirrel":false}, { "events": ["lettuce", "brushed teeth", "running", "work"], "squirrel": false },
{"events":["candy","brushed teeth","work"],"squirrel":false}, { "events": ["candy", "brushed teeth", "work"], "squirrel": false },
{"events":["brussel sprouts","brushed teeth","computer","work"],"squirrel":false}, { "events": ["brussel sprouts", "brushed teeth", "computer", "work"], "squirrel": false },
{"events":["bread","brushed teeth","weekend"],"squirrel":false}, { "events": ["bread", "brushed teeth", "weekend"], "squirrel": false },
{"events":["cauliflower","brushed teeth","weekend"],"squirrel":false}, { "events": ["cauliflower", "brushed teeth", "weekend"], "squirrel": false },
{"events":["spaghetti","candy","television","work","touched tree"],"squirrel":false}, { "events": ["spaghetti", "candy", "television", "work", "touched tree"], "squirrel": false },
{"events":["carrot","pudding","brushed teeth","work"],"squirrel":false}, { "events": ["carrot", "pudding", "brushed teeth", "work"], "squirrel": false },
{"events":["lettuce","brushed teeth","work"],"squirrel":false}, { "events": ["lettuce", "brushed teeth", "work"], "squirrel": false },
{"events":["carrot","ice cream","brushed teeth","cycling","work"],"squirrel":false}, { "events": ["carrot", "ice cream", "brushed teeth", "cycling", "work"], "squirrel": false },
{"events":["pizza","brushed teeth","work"],"squirrel":false}, { "events": ["pizza", "brushed teeth", "work"], "squirrel": false },
{"events":["spaghetti","peanuts","exercise","weekend"],"squirrel":true}, { "events": ["spaghetti", "peanuts", "exercise", "weekend"], "squirrel": true },
{"events":["bread","beer","computer","weekend","touched tree"],"squirrel":false}, { "events": ["bread", "beer", "computer", "weekend", "touched tree"], "squirrel": false },
{"events":["brushed teeth","running","work"],"squirrel":false}, { "events": ["brushed teeth", "running", "work"], "squirrel": false },
{"events":["lettuce","peanuts","brushed teeth","work","touched tree"],"squirrel":false}, { "events": ["lettuce", "peanuts", "brushed teeth", "work", "touched tree"], "squirrel": false },
{"events":["lasagna","brushed teeth","television","work"],"squirrel":false}, { "events": ["lasagna", "brushed teeth", "television", "work"], "squirrel": false },
{"events":["cauliflower","brushed teeth","running","work"],"squirrel":false}, { "events": ["cauliflower", "brushed teeth", "running", "work"], "squirrel": false },
{"events":["carrot","brushed teeth","running","work"],"squirrel":false}, { "events": ["carrot", "brushed teeth", "running", "work"], "squirrel": false },
{"events":["carrot","reading","weekend"],"squirrel":false}, { "events": ["carrot", "reading", "weekend"], "squirrel": false },
{"events":["carrot","peanuts","reading","weekend"],"squirrel":true}, { "events": ["carrot", "peanuts", "reading", "weekend"], "squirrel": true },
{"events":["potatoes","brushed teeth","running","work"],"squirrel":false}, { "events": ["potatoes", "brushed teeth", "running", "work"], "squirrel": false },
{"events":["lasagna","ice cream","work","touched tree"],"squirrel":false}, { "events": ["lasagna", "ice cream", "work", "touched tree"], "squirrel": false },
{"events":["cauliflower","peanuts","brushed teeth","cycling","work"],"squirrel":false}, { "events": ["cauliflower", "peanuts", "brushed teeth", "cycling", "work"], "squirrel": false },
{"events":["pizza","brushed teeth","running","work"],"squirrel":false}, { "events": ["pizza", "brushed teeth", "running", "work"], "squirrel": false },
{"events":["lettuce","brushed teeth","work"],"squirrel":false}, { "events": ["lettuce", "brushed teeth", "work"], "squirrel": false },
{"events":["bread","brushed teeth","television","weekend"],"squirrel":false}, { "events": ["bread", "brushed teeth", "television", "weekend"], "squirrel": false },
{"events":["cauliflower","peanuts","brushed teeth","weekend"],"squirrel":false} { "events": ["cauliflower", "peanuts", "brushed teeth", "weekend"], "squirrel": false }
]; ];
function tableFor(event, journal) { function tableFor(event, journal) {
let table = [0,0,0,0]; let table = [0, 0, 0, 0];
for (let i = 0; i < journal.length; i++) { for (let i = 0; i < journal.length; i++) {
let entry = journal[i], index = 0; let entry = journal[i], index = 0;
if (entry.events.includes(event)) index += 1; if (entry.events.includes(event)) index += 1;
if (entry.squirrel) index += 2; if (entry.squirrel) index += 2;
table[index] += 1; table[index] += 1;
}
return table;
} }
return table;
}
console.log(tableFor("pizza", JOURNAL)); console.log(tableFor("pizza", JOURNAL));
function phi(table) { function phi(table) {
return (table[3] * table[0] - table[2] * table[1]) / Math.sqrt( return (table[3] * table[0] - table[2] * table[1]) / Math.sqrt(
(table[2] + table[3]) * (table[2] + table[3]) *
(table[0] + table[1]) * (table[0] + table[1]) *
(table[1] + table[3]) * (table[1] + table[3]) *
(table[0] + table[2])); (table[0] + table[2]));
}; };
function journalEvents(journal){ function journalEvents(journal) {
let events = []; let events = [];
for (let entry of journal){ for (let entry of journal) {
for (let event of entry.events){ for (let event of entry.events) {
if (!events.includes(event)){ if (!events.includes(event)) {
events.push(event); events.push(event);
} }
} }
@ -126,9 +126,17 @@ function journalEvents(journal){
} }
console.log(journalEvents(JOURNAL)); console.log(journalEvents(JOURNAL));
for (let event of journalEvents(JOURNAL)){ for (let event of journalEvents(JOURNAL)) {
let correlation = phi(tableFor(event, JOURNAL)); let correlation = phi(tableFor(event, JOURNAL));
if (correlation > 0.1 || correlation < -0.1){ if (correlation > 0.1 || correlation < -0.1) {
console.log(event + ":", correlation) console.log(event + ":", correlation)
} }
} }
for (let entry of JOURNAL) {
if (entry.events.includes("peanuts") &&
!entry.events.includes("brushed teeth")) {
entry.events.push('peanut teeth');
}
}
console.log(phi(tableFor("peanut teeth", JOURNAL)));

View file

@ -0,0 +1,50 @@
let todoList = [];
function remember(task) {
todoList.push(task)
}
function getTask() {
return todoList.shift();
}
function rememberUrgently(task) {
todoList.unshift(task)
}
// remember("groceries");
// remember("sleep");
// console.log(todoList);
// console.log(getTask());
// rememberUrgently("eat");
// remember("run");
// console.log(todoList);
// console.log(todoList.indexOf(2));
function remove(array, index) {
return array.slice(0, index)
.concat(array.slice(index + 1));
}
// console.log(remove(["a", "b", "c", "d", "e"], 2));
let sentence = "Secretarybirds specialize in stomping";
let words = sentence.split(" ");
// console.log(words);
// console.log(words.join(". "));
function max(...numbers) {
let result = -Infinity;
for (let number of numbers) {
if (number > result) result = number;
}
return result;
}
let numbers = [4, 1, 9, -22, 14, 69, 1337];
console.log(max(...numbers));
function randomPointOnCircle(radius) {
let angle = Math.random() * 2 * Math.PI;
return {
x: radius * Math.cos(angle),
y: radius * Math.sin(angle)
};
}
console.log(randomPointOnCircle(2));