diff --git a/oppgaver/uke6/8ball/controller.js b/oppgaver/uke6/8ball/controller.js index e69de29..8ddb1a9 100644 --- a/oppgaver/uke6/8ball/controller.js +++ b/oppgaver/uke6/8ball/controller.js @@ -0,0 +1,17 @@ +function pickRandomAnswer(){ + answerArray = [AffirmativeAnswers, nonCommittalAnswers, negativeAnswers]; + + randomAnswersArrary = answerArray[Math.floor(Math.random() * answerArray.length)]; + + randomAnswer = randomAnswersArrary[Math.floor(Math.random() * randomAnswersArrary.length)] + htmlAnswer = /*HTML*/ ` +
Question:

+
Answer: ${randomAnswer}
+ `; + clearScreen(); + updateView(); +} + +function clearScreen(){ + app.innerHTML = ''; +} \ No newline at end of file diff --git a/oppgaver/uke6/8ball/model.js b/oppgaver/uke6/8ball/model.js index af66c56..5a32c0a 100644 --- a/oppgaver/uke6/8ball/model.js +++ b/oppgaver/uke6/8ball/model.js @@ -1,2 +1,29 @@ -const eightBall = []; -var app = document.getElementById('app') \ No newline at end of file + +var app = document.getElementById('app') +const AffirmativeAnswers = [ + 'It is certain', 'It is decidedly so', + 'Without a doubt', 'Yes definitely', + 'You may rely on it', 'As I see it, yes', + 'Most likely', 'Outlook good', + 'Yes', 'Signs point to yes' +]; +const nonCommittalAnswers = [ + 'Reply hazy, try again', 'Ask again later', + 'Better not tell you now', 'Cannot predict now', + 'Concentrate and ask again' +]; +const negativeAnswers = [ + 'Don\’t count on it', 'My reply is no', + 'My sources say no', 'Outlook not so good', + 'Very doubtful' +]; +var html = /*HTML*/` +
8-ball
+ Ask Your question:
+ +`; +var htmlAnswer = ''; + +var answerArray = []; +var randomAnswersArrary = []; +var randomAnswer; \ No newline at end of file diff --git a/oppgaver/uke6/8ball/unit_testing.html b/oppgaver/uke6/8ball/unit_testing.html new file mode 100644 index 0000000..9d04992 --- /dev/null +++ b/oppgaver/uke6/8ball/unit_testing.html @@ -0,0 +1,27 @@ + + + +QUnit + + + +
+
+ + + + + + \ No newline at end of file diff --git a/oppgaver/uke6/8ball/view.js b/oppgaver/uke6/8ball/view.js index ae6f86d..24ae08c 100644 --- a/oppgaver/uke6/8ball/view.js +++ b/oppgaver/uke6/8ball/view.js @@ -1,7 +1,4 @@ updateView(); function updateView(){ - let html = /*HTML*/ ` -
8-ball
- `; - app.innerHTML = html; + app.innerHTML = html + htmlAnswer; } \ No newline at end of file