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';
// } else {
// extraWord = '';
// }
document.getElementById('app').innerHTML = /*HTML*/ ` document.getElementById('app').innerHTML = /*HTML*/ `
<h1>Min app</h1> <p>Hei ${aName ?? 'på deg!'}</p>
${message} Navn:<br>
<button>Vis sukksess</button> <input
<button>Vis advarsel</button> type="text"
<button></button> oninput="aName=this.value"
<button>1</button> 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

@ -132,3 +132,11 @@ for (let event of journalEvents(JOURNAL)){
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));