Pavel 7 anni fa
parent
commit
700e33c6e7
1 ha cambiato i file con 10 aggiunte e 21 eliminazioni
  1. 10 21
      js02-part2/js02-part2.md

+ 10 - 21
js02-part2/js02-part2.md

@@ -196,42 +196,31 @@ switch(task){
 		alert(result.toFixed(2) + " " +cur);
 			break;
 	case "scissors":
+		var arr = ['камень', 'ножницы', 'бумага'];
 		var userVar = prompt("Введите одно из 3х - 'камень', 'ножницы', 'бумага'");
-		var computerVar = Math.floor(Math.random() * 3);
-		var computerVarText;
-		switch(computerVar){
-			case 0: 
-				computerVarText = "камень";
-				break;
-			case 1: 
-				computerVarText = "ножницы";
-				break;
-			case 2: 
-				computerVarText = "бумага";
-				break;		
-		}
+		var computerVar = arr[Math.floor(Math.random() * 3)];
 
-		alert("Зачение компьютера: " + computerVarText);
+		alert("Зачение компьютера: " + computerVar);
 
-		if(userVar === computerVarText){
+		if(userVar === computerVar){
 			alert("Ничья");
 		}
-		else if (userVar === "камень" && computerVarText === "бумага"){
+		else if (userVar === arr[0] && computerVar === arr[2]){
 			alert("Вы проиграли");
 		}
-		else if (userVar === "камень" && computerVarText === "ножницы"){
+		else if (userVar === arr[0] && computerVar === arr[1]){
 			alert("Вы выиграли");
 		}
-		else if (userVar === "бумага" && computerVarText === "камень"){
+		else if (userVar === arr[2] && computerVar === arr[0]){
 			alert("Вы выиграли");
 		}
-		else if (userVar === "бумага" && computerVarText === "ножницы"){
+		else if (userVar === arr[2] && computerVar === arr[1]){
 			alert("Вы проиграли");
 		}
-		else if (userVar === "ножницы" && computerVarText === "камень"){
+		else if (userVar === arr[1] && computerVar === arr[0]){
 			alert("Вы проиграли");
 		}
-		else if (userVar === "ножницы" && computerVarText === "бумага"){
+		else if (userVar === arr[1] && computerVar === arr[2]){
 			alert("Вы выиграли");
 		}
 			break;