fixed random variables
This commit is contained in:
parent
af1354ff9c
commit
5e820e89a3
|
@ -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*/ `
|
||||||
|
<div>Question: </div><br>
|
||||||
|
<div>Answer: ${randomAnswer}</div>
|
||||||
|
`;
|
||||||
|
clearScreen();
|
||||||
|
updateView();
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearScreen(){
|
||||||
|
app.innerHTML = '';
|
||||||
|
}
|
|
@ -1,2 +1,29 @@
|
||||||
const eightBall = [];
|
|
||||||
var app = document.getElementById('app')
|
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*/`
|
||||||
|
<div id="ball">8-ball</div>
|
||||||
|
Ask Your question: <input type="text" /><br>
|
||||||
|
<button onclick="pickRandomAnswer()">Submit</button>
|
||||||
|
`;
|
||||||
|
var htmlAnswer = '';
|
||||||
|
|
||||||
|
var answerArray = [];
|
||||||
|
var randomAnswersArrary = [];
|
||||||
|
var randomAnswer;
|
27
oppgaver/uke6/8ball/unit_testing.html
Normal file
27
oppgaver/uke6/8ball/unit_testing.html
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>QUnit</title>
|
||||||
|
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.22.0.css">
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="qunit"></div>
|
||||||
|
<div id="qunit-fixture"></div>
|
||||||
|
<script src="https://code.jquery.com/qunit/qunit-2.22.0.js"></script>
|
||||||
|
<script src="controller.js"></script>
|
||||||
|
<script>
|
||||||
|
QUnit.test('Answer', function (assert) {
|
||||||
|
// arrange
|
||||||
|
let AffirmativeAnswers = ['hello'];
|
||||||
|
|
||||||
|
// act
|
||||||
|
|
||||||
|
let returnedText = pickRandomAnswer();
|
||||||
|
|
||||||
|
// assert
|
||||||
|
assert.equal(returnedText, 'hello');
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
|
@ -1,7 +1,4 @@
|
||||||
updateView();
|
updateView();
|
||||||
function updateView(){
|
function updateView(){
|
||||||
let html = /*HTML*/ `
|
app.innerHTML = html + htmlAnswer;
|
||||||
<div id="ball">8-ball</div>
|
|
||||||
`;
|
|
||||||
app.innerHTML = html;
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue