maryluis 4 лет назад
Родитель
Сommit
91c033212d
1 измененных файлов с 28 добавлено и 38 удалено
  1. 28 38
      homework5js/script.js

+ 28 - 38
homework5js/script.js

@@ -107,7 +107,6 @@ function declarativeFriends() {
 //////////////
 
 
-/////Я толком не поняла что имеется ввиду, потому написала два варианта, надеюсь хоть один из них верный.
 /////imperative array fill 3
 function imperativeArray() {
     let imperative = [];
@@ -116,12 +115,6 @@ function imperativeArray() {
 }
 // imperativeArray()
 ////////
-function imperativeArray2() {
-    var imperative = [];
-    imperative.push((prompt("How old are you?")),(prompt("How old is your father?")), (prompt("How old is your father?")));
-    alert("So you are " + imperative[0] + " years old. Your father is " + imperative[1] + " and mother is " + imperative[2])
-}
-// imperativeArray2()
 
 
 
@@ -144,7 +137,7 @@ function whileConfirm(question) {
 function arrayFill() {
     var array = [];
     var once = true;
-    while(!!once === true) {
+    while(!!once === true || once === "") {
         once = prompt("Write something")
         array.push(once)
     }
@@ -159,7 +152,7 @@ function arrayFillNopush() {
     var i = 0;
     var array = [];
     var once = prompt("Write something");
-    while(!!once === true) {
+    while(!!once === true || once === "") {
         array[i++] = once;
         once = prompt("Write something");
     } 
@@ -192,8 +185,8 @@ alert ("You had " + array.length + " expected output")
 ///////empty loop
 function emptyLoop() {
     var again = null;
-    while(again === null) {
-        again = prompt("And again?")
+    while((again = prompt("And again?")) === null) {
+
     }
 }
 // emptyLoop()
@@ -375,33 +368,30 @@ function blueBelt() {
 
 ////////////////
 //blackBelt
-debugger
-var predictArray = [];
+var predictArray = [[-1]];
 var historyArr = [1, 1, 1, 1];
 var myMove = Math.round(Math.random());
 
-// function blackBelt(history) {
-//     var yourMove = +prompt("Your move (0 or 1");
-//     if (yourMove === 1 || yourMove === 0) {
-        
-//         historyArr.shift();
-//         historyArr.push(yourMove);
-
-//         myMove = predictArray[historyArr[0]][historyArr[1]][historyArr[2]][historyArr[3]];
-
-//         predictArray[historyArr[0]][historyArr[1]][historyArr[2]][historyArr[3]] = yourMove;
-
-
-//         if (myMove === yourMove){
-//             alert("I knew it. Let's try again")
-//             return blackBelt()
-//         } else {
-//             alert ("You win. Let's try again")
-//             return blackBelt()
-//         }
-//     } else {
-//         alert ("Error. Try again")
-//         return blackBelt()
-//     }
-// }
-// blackBelt(historyArr);
+function blackBelt() {
+    var yourMove = +prompt("Your move 0 or 1");
+    var answer;
+    if (yourMove === 1 || yourMove === 0) {
+        if (myMove === yourMove){
+            answer = confirm("I knew it. Let's try again");
+
+        } else {
+            answer = confirm ("You win. Let's try again");
+
+        }
+        myMove = predictArray[0][0];
+        predictArray = [[historyArr[0]],[historyArr[1]],[historyArr[2]],[historyArr[3]]]; 
+        historyArr.shift();
+        historyArr.push(yourMove); 
+        if(answer == true) {
+            return blackBelt()
+        }
+    } else {
+        alert ("Error. Try again")
+    }
+}
+// blackBelt();