@@ -42,7 +42,7 @@ let firstRun = true;
42
42
function Start ( )
43
43
{
44
44
minValue = parseInt ( minValueField . value ) || 0 ;
45
- maxValue = parseInt ( maxValueField . value ) || 100 ;
45
+ maxValue = parseInt ( maxValueField . value ) === 0 ? 0 : parseInt ( maxValueField . value ) || 100 ;
46
46
47
47
if ( minValue > maxValue )
48
48
{
@@ -60,13 +60,10 @@ function Start()
60
60
61
61
orderNumberField . innerText = orderNumber ++ ;
62
62
answerField . innerText = `${ nextAnswerPhrases [ 0 ] } ${ IntToText ( answerNumber ) } ?` ;
63
-
64
- if ( firstRun )
65
- {
66
- modalStartAlertText . innerText = `Загадайте любое целое число от ${ minValue } до ${ maxValue } , а я его угадаю` ;
67
- modalStartAlert . modal ( "show" ) ;
68
- firstRun = false ;
69
- }
63
+
64
+ modalStartAlertText . innerText = `Загадайте любое целое число от ${ minValue } до ${ maxValue } , а я его угадаю` ;
65
+ modalStartAlert . modal ( "show" ) ;
66
+ firstRun = false ;
70
67
}
71
68
72
69
// Перевод числовой записи в пропись
@@ -165,19 +162,24 @@ document.querySelector('#btnOver').addEventListener('click', function () {
165
162
// Кнопка меньше
166
163
document . querySelector ( '#btnLess' ) . addEventListener ( 'click' , function ( ) {
167
164
if ( gameRun ) {
168
- if ( minValue === maxValue ) { // Игрок сжулничал и давал не правильные ответы
169
- const phraseRandom = Math . round ( Math . random ( ) * ( failAnswerPhrases . length - 1 ) ) ;
170
- const answerPhrase = failAnswerPhrases [ phraseRandom ] ;
171
- answerField . innerText = answerPhrase ;
172
- gameRun = false ;
173
- } else { //Продолжить поиск ниже
165
+ if ( minValue !== maxValue ) { //Продолжить поиск ниже
174
166
maxValue = answerNumber - 1 ;
175
- answerNumber = Math . floor ( ( minValue + maxValue ) / 2 ) ;
176
- orderNumberField . innerText = orderNumber ++ ;
167
+ if ( maxValue >= minValue )
168
+ {
169
+ answerNumber = Math . ceil ( ( minValue + maxValue ) / 2 ) ;
170
+ orderNumberField . innerText = orderNumber ++ ;
177
171
178
- const phraseRandom = Math . round ( Math . random ( ) * ( nextAnswerPhrases . length - 1 ) ) ;
179
- answerField . innerText = `${ nextAnswerPhrases [ phraseRandom ] } ${ IntToText ( answerNumber ) } ?` ;
180
- }
172
+ const phraseRandom = Math . round ( Math . random ( ) * ( nextAnswerPhrases . length - 1 ) ) ;
173
+ answerField . innerText = `${ nextAnswerPhrases [ phraseRandom ] } ${ IntToText ( answerNumber ) } ?` ;
174
+ return ;
175
+ }
176
+ }
177
+ // Игрок сжулничал и давал не правильные ответы
178
+ const phraseRandom = Math . round ( Math . random ( ) * ( failAnswerPhrases . length - 1 ) ) ;
179
+ const answerPhrase = failAnswerPhrases [ phraseRandom ] ;
180
+ answerField . innerText = answerPhrase ;
181
+ gameRun = false ;
182
+
181
183
}
182
184
} ) ;
183
185
0 commit comments