Skip to content

Commit 826ede5

Browse files
committed
new add
1 parent e2362e5 commit 826ede5

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

bjs/08_if_else/script.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ document.getElementById('btnRetry').addEventListener('click', function () {
1515
minValue = 0;
1616
maxValue = 100;
1717
orderNumber = 0;
18+
1819
})
1920

2021
document.getElementById('btnOver').addEventListener('click', function () {
2122
if (gameRun){
2223
if (minValue === maxValue){
23-
const phraseRandom = Math.round( Math.random());
24+
const phraseRandom = Math.round( Math.random() * 3);
2425
const answerPhrase = (phraseRandom === 1) ?
2526
`Вы загадали неправильное число!\n\u{1F914}` :
2627
`Я сдаюсь..\n\u{1F92F}`;
@@ -37,6 +38,28 @@ document.getElementById('btnOver').addEventListener('click', function () {
3738
}
3839
})
3940

41+
document.getElementById('btnLess').addEventListener('click', function () {
42+
if (gameRun){
43+
if (minValue === maxValue){
44+
const phraseRandom = Math.round( Math.random() * 3);
45+
const answerPhrase = (phraseRandom === 1) ?
46+
`Вы загадали неправильное число!\n\u{1F914}` :
47+
`Я сдаюсь..\n\u{1F92F}`;
48+
49+
answerField.innerText = answerPhrase;
50+
gameRun = false;
51+
} else {
52+
maxValue = answerNumber + 0;
53+
answerNumber = Math.floor((minValue + maxValue) / 2);
54+
orderNumber++;
55+
orderNumberField.innerText = orderNumber;
56+
answerField.innerText = `Вы загадали число ${answerNumber }?`;
57+
}
58+
}
59+
})
60+
61+
62+
4063
document.getElementById('btnEqual').addEventListener('click', function () {
4164
if (gameRun){
4265
answerField.innerText = `Я всегда угадываю\n\u{1F60E}`

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<nav>
1212
<ul>
1313
<li><a href="bjs/07_Number_and_string/index.html">Calculator</a></li>
14-
<li><a href="bjs/08_if_else/index.html">if else</a></li>
14+
<li><a href="bjs/08_if_else/index.html">Game</a></li>
1515
<li><a href="bjs/10_function_object/index.html">function</a></li>
1616
</ul>
1717
</nav>

0 commit comments

Comments
 (0)