Commit 33e27385 authored by Felix Felbermayer's avatar Felix Felbermayer
Browse files

Lint all files

parent 2793105a
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: [
'airbnb-base',
],
parserOptions: {
ecmaVersion: 12,
sourceType: 'module',
},
rules: {
},
};
export function delay(){
return new Promise(function(resolve){
setTimeout(resolve, 200)
})
}
\ No newline at end of file
/* eslint-disable */
export function delay() {
return new Promise((resolve) => {
setTimeout(resolve, 200);
});
}
/* eslint-enable */
// index.js
import { getQuestions } from './questions.js'
import {askQuestion, answerQuestion} from './quiz.js'
window.addEventListener('load', function () {
const onRender = async (id) =>{
const {pathname} = window.location
if(pathname==='/'){
let hide=document.getElementById('goHome')
let nothide=document.getElementById('goQuiz')
hide.style.display="none";
nothide.style.display="initial";
document.getElementById('question').innerHTML=''
document.getElementById('answer').innerHTML=''
document.getElementById('result').innerHTML=''
}else if(pathname==='/quiz'){
window.question = await askQuestion()
console.log(window.question)
displayQuiz(window.question)
let hide=document.getElementById('goQuiz')
hide.style.display="none";
}else if(pathname==='/result' && id != undefined){
let nothide=document.getElementById('goHome')
nothide.style.display="initial";
}
else{
document.getElementById('content').innerHTML='not found'
}
/* eslint-disable */
import { askQuestion, answerQuestion } from './quiz.js';
/* eslint-enable */
window.addEventListener('load', () => {
const onRender = async (id) => {
const { pathname } = window.location;
if (pathname === '/') {
const hide = document.getElementById('goHome');
const nothide = document.getElementById('goQuiz');
hide.style.display = 'none';
nothide.style.display = 'initial';
document.getElementById('question').innerHTML = '';
document.getElementById('answer').innerHTML = '';
document.getElementById('result').innerHTML = '';
} else if (pathname === '/quiz') {
window.question = await askQuestion();
/* eslint-disable */
displayQuiz(window.question);
/* eslint-enable */
const hide = document.getElementById('goQuiz');
hide.style.display = 'none';
} else if (pathname === '/result' && id !== undefined) {
const nothide = document.getElementById('goHome');
nothide.style.display = 'initial';
} else {
document.getElementById('content').innerHTML = 'not found';
}
onRender();
Array.from(document.querySelectorAll('a'))[0].addEventListener('click',(evt) => {
evt.preventDefault()
history.pushState({}, 'quiz', '/quiz')
onRender("")
})
Array.from(document.querySelectorAll('a'))[1].addEventListener('click',(evt) => {
evt.preventDefault()
history.pushState({}, 'home', '/')
onRender("")
})
document.getElementById('answer').addEventListener('click', (evt) => {
evt.preventDefault()
history.pushState({}, 'result', '/result')
onRender(evt.target.id)
displayAnswer(window.question, evt.target.id)
})
})
function createQuizItem(content,num) {
let p = document.createElement('a');
p.setAttribute("href", "");
p.setAttribute("id", num);
p.setAttribute("class", "answer");
p.textContent = content;
return p;
};
onRender();
Array.from(document.querySelectorAll('a'))[0].addEventListener('click', (evt) => {
evt.preventDefault();
/* eslint-disable */
history.pushState({}, 'quiz', '/quiz');
/* eslint-enable */
onRender('');
});
Array.from(document.querySelectorAll('a'))[1].addEventListener('click', (evt) => {
evt.preventDefault();
/* eslint-disable */
history.pushState({}, 'home', '/');
/* eslint-enable */
onRender('');
});
document.getElementById('answer').addEventListener('click', (evt) => {
evt.preventDefault();
/* eslint-disable */
history.pushState({}, 'result', '/result');
onRender(evt.target.id);
displayAnswer(window.question, evt.target.id);
/* eslint-enable */
});
});
function createQuizItem(content, num) {
const p = document.createElement('a');
p.setAttribute('href', '');
p.setAttribute('id', num);
p.setAttribute('class', 'answer');
p.textContent = content;
return p;
}
function createQuestion(content) {
let p = document.createElement('p');
p.textContent = content;
return p;
const p = document.createElement('p');
p.textContent = content;
return p;
}
async function displayQuiz(question){
document.getElementById('question').appendChild(createQuestion(question.question))
document.getElementById('answer').appendChild(createQuizItem('a: '+question.a,'a'))
document.getElementById('answer').appendChild(createQuizItem('b: '+question.b,'b'))
document.getElementById('answer').appendChild(createQuizItem('c: '+question.c,'c'))
document.getElementById('answer').appendChild(createQuizItem('d: '+question.d,'d'))
async function displayQuiz(question) {
document.getElementById('question').appendChild(createQuestion(question.question));
document.getElementById('answer').appendChild(createQuizItem(`a: ${question.a}`, 'a'));
document.getElementById('answer').appendChild(createQuizItem(`b: ${question.b}`, 'b'));
document.getElementById('answer').appendChild(createQuizItem(`c: ${question.c}`, 'c'));
document.getElementById('answer').appendChild(createQuizItem(`d: ${question.d}`, 'd'));
}
async function displayAnswer(question, answer){
console.log(question)
const ans = await answerQuestion(question, answer)
if(ans === true){
document.getElementById('result').appendChild(createQuestion('Correct answer!🥳'))
document.getElementById('question').innerHTML=''
document.getElementById('answer').innerHTML=''
}else{
document.getElementById('result').appendChild(createQuestion('Wrong answer!😢'))
document.getElementById('question').innerHTML=''
document.getElementById('answer').innerHTML=''
}
async function displayAnswer(question, answer) {
const ans = await answerQuestion(question, answer);
if (ans === true) {
document.getElementById('result').appendChild(createQuestion('Correct answer!🥳'));
document.getElementById('question').innerHTML = '';
document.getElementById('answer').innerHTML = '';
} else {
document.getElementById('result').appendChild(createQuestion('Wrong answer!😢'));
document.getElementById('question').innerHTML = '';
document.getElementById('answer').innerHTML = '';
}
}
This diff is collapsed.
......@@ -4,11 +4,17 @@
"description": "",
"main": "index.js",
"scripts": {
"start": "http-server --proxy http://localhost:8080"
"start": "http-server --proxy http://localhost:8080",
"lint": "npx eslint ."
},
"author": "",
"license": "ISC",
"dependencies": {
"http-server": "^0.12.3"
},
"devDependencies": {
"eslint": "^7.16.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.22.1"
}
}
import {delay} from './delay.js'
let questions=[
{
"question" : "Wie nennt man ein Selfie, das nur die Schuhe zeigt?",
"correctAnswer" : "a",
"a" : "Shoefie",
"b" : "Shelfie",
"c" : "Selfoe",
"d" : "Footfie"
},
{
"question" : "In welchem Hotel in Paris wohnte Coco Channel?",
"correctAnswer" : "c",
"a" : "Marriot",
"b" : "Hilton",
"c" : "Ritz",
"d" : "Plaza Athénée Paris"
},
{
"question" : "Welche ist die meistgefälschte Marke der Welt?",
"correctAnswer" : "a",
"a" : "Nike",
"b" : "Beats by Dr. Dre",
"c" : "Luis Vitton",
"d" : "Jbl"
},
{
"question" : "Durch welche Musik lassen sich Weiße Haie anlocken.",
"correctAnswer" : "b",
"a" : "Hip-Hop",
"b" : "Death Metal",
"c" : "Schlager",
"d" : "Pop"
},
{
"question" : "Was ist ein Anzeichen dafür, dass Koalas gestresst sind?",
"correctAnswer" : "d",
"a" : "Gibt keine anzeichen",
"b" : "Sie fallen vom Baum",
"c" : "Sie fiepsen hysterisch",
"d" : "Sie Bekommen Schluckauf"
}
];
export async function getQuestions(){
await delay();
return questions
}
\ No newline at end of file
/* eslint-disable */
import delay from './delay.js';
/* eslint-enable */
const questions = [
{
question: 'Wie nennt man ein Selfie, das nur die Schuhe zeigt?',
correctAnswer: 'a',
a: 'Shoefie',
b: 'Shelfie',
c: 'Selfoe',
d: 'Footfie',
},
{
question: 'In welchem Hotel in Paris wohnte Coco Channel?',
correctAnswer: 'c',
a: 'Marriot',
b: 'Hilton',
c: 'Ritz',
d: 'Plaza Athénée Paris',
},
{
question: 'Welche ist die meistgefälschte Marke der Welt?',
correctAnswer: 'a',
a: 'Nike',
b: 'Beats by Dr. Dre',
c: 'Luis Vitton',
d: 'Jbl',
},
{
question: 'Durch welche Musik lassen sich Weiße Haie anlocken.',
correctAnswer: 'b',
a: 'Hip-Hop',
b: 'Death Metal',
c: 'Schlager',
d: 'Pop',
},
{
question: 'Was ist ein Anzeichen dafür, dass Koalas gestresst sind?',
correctAnswer: 'd',
a: 'Gibt keine anzeichen',
b: 'Sie fallen vom Baum',
c: 'Sie fiepsen hysterisch',
d: 'Sie Bekommen Schluckauf',
},
];
/* eslint-disable */
export async function getQuestions() {
await delay();
return questions;
}
/* eslint-enable */
import {getQuestions} from './questions.js'
export async function askQuestion(){
const questions = await getQuestions();
let rnd = Math.floor(Math.random() * Math.floor(5));
return questions[rnd]
}
export async function answerQuestion(question, a){
if(question.correctAnswer === a) return true
else return false
}
/* eslint-disable */
import getQuestions from './questions.js';
/* eslint-enable */
export async function askQuestion() {
const questions = await getQuestions();
const rnd = Math.floor(Math.random() * Math.floor(5));
return questions[rnd];
}
export async function answerQuestion(question, a) {
if (question.correctAnswer === a) return true;
return false;
}
Markdown is supported
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