Commit 28ca4012 authored by Sander Kvenild's avatar Sander Kvenild
Browse files

Merge branch 'master' of gitlab.stud.idi.ntnu.no:sandekv/dcst1007-oop

parents 04127961 c2c9fa43
......@@ -61,8 +61,7 @@
// Ny kode
async function tallOver10(tall) {
return new Promise(
(resolve, reject) => {
console.log(2, tall);
resolve => {
if (tall > 10) {
resolve("Tallet er over 10");
}
......@@ -83,27 +82,70 @@
(resolve, reject) => {
for (i = 0; i < stringArray.length; i++) {
if (/[^a-zA-ZæøåÆØÅ]/.test(stringArray[i])) {
var reason = new Error(`Element: ${i} inneholder symboler som ikke er bokstaver!`);
var reason = new Error(`Element[${i}]: med verdi "${stringArray[i]}" inneholder symboler som ikke er bokstaver!`);
reject(reason);
return;
}
}
stringArray = stringArray.map((e) => e.toUpperCase())
resolve(`[${stringArray.join(", ")}]`);
resolve(stringArray);
}
)
}
async function sort(stringArray) {
return new Promise(
(resolve, reject) => {
for (i = 0; i < stringArray.length; i++) {
if (/[^a-zA-ZæøåÆØÅ]/.test(stringArray[i])) {
var reason = new Error(`Element[${i}]: med verdi "${stringArray[i]}" inneholder symboler som ikke er bokstaver!`);
reject(reason);
}
}
stringArray = stringArray.sort();
resolve(stringArray);
}
)
}
async function showGithubAvatar(username) {
const requestURL = `https://api.github.com/users/${username}`;
const request = new Request(requestURL);
const response = await fetch(request);
if (response.status == 404) {
throw new Error(`User '${username}'' doesn't exist`);
return;
}
const userJSON = await response.json();
utdata.innerHTML += `<br><img src=${userJSON.avatar_url} />`;
}
// Kode som kjører funksjonene
(async () => {
await hvaSierMamma();
utdata.innerHTML += "<br>";
await testTall(2);
await testTall(15);
await testTall(10);
utdata.innerHTML += "<br>";
let temp = await lagStoreBokstaver(["abcdefg", "sander", ""]);
utdata.innerHTML += "<br>" + temp;
try {
let storeBokstaver = await lagStoreBokstaver(["abcdefg", "test", "æøå", "sorttest"]);
let sortertArray = await sort(storeBokstaver);
utdata.innerHTML += "<br>" + sortertArray;
} catch (error) {
utdata.innerHTML += "<br>" + error.message;
}
utdata.innerHTML += "<br>";
try {
await showGithubAvatar("remy");
} catch (error) {
utdata.innerHTML += "<br>" + error.message;
}
})();
</script>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment