Студопедия
Случайная страница | ТОМ-1 | ТОМ-2 | ТОМ-3
АрхитектураБиологияГеографияДругоеИностранные языки
ИнформатикаИсторияКультураЛитератураМатематика
МедицинаМеханикаОбразованиеОхрана трудаПедагогика
ПолитикаПравоПрограммированиеПсихологияРелигия
СоциологияСпортСтроительствоФизикаФилософия
ФинансыХимияЭкологияЭкономикаЭлектроника

Камень, ножницы, бумага

Читайте также:
  1. Бумага для печати
  2. Бумага на покрывной материал
  3. в том числе бездокументарными ценными бумагами
  4. Восстановление прав по утраченным ценным бумагам на предъявителя или ордерным ценным бумагам (вызывное производство)
  5. КАМЕНЬ, КОТОРЫЙ ОТВЕРГЛИ СТРОИТЕЛИ 1 страница
  6. КАМЕНЬ, КОТОРЫЙ ОТВЕРГЛИ СТРОИТЕЛИ 2 страница
  7. КАМЕНЬ, КОТОРЫЙ ОТВЕРГЛИ СТРОИТЕЛИ 3 страница

var result = "";

 

var player = prompt("Pick rock, paper, or scissors.");

// If the player types "ROCK," the script needs to read that the same

// as "rock", but only if player!== null!

if(player!== null) {

player.toLowerCase();

}

 

var choices = ["rock","paper","scissors"];

var computer = choices[Math.floor(Math.random()*3)];

 

var win = "Your "+player+" beats "+computer+". You win.";

var lose = "Your "+player+" loses to "+computer+". You lose.";

var draw = "A draw: "+player+" on "+computer+".";

 

if(player === "rock"){

if(computer === "scissors"){

result = win;

}

else if(computer === "paper"){

result = lose;

}

else if(computer === "rock"){

result = draw;

}

}

else if(player === "paper"){

if(computer === "rock"){

result = win;

}

else if(computer === "scissors"){

result = lose;

}

else if(computer === "paper"){

result = draw;

}

}

else if(player === "scissors"){

if(computer === "paper"){

result = win;

}

else if(computer === "rock"){

result = lose;

}

else if(computer === "scissors"){

result = draw;

}

}

// If the player clicks cancel, the 'result' should equal "Bye!"

else if (player===null){

console.log("Bye!");

}

 

// If the player enters any other string, 'result' should equal

// "I said rock, paper, or scissors!"

else {

console.log("I said rock, paper, or scissors!");

}

console.log(result);

 

_____________________________________________________________________________________

Sort an array:

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.sort();

 

 

// Write `compareStrLength` function

var compareStringLength = function (string1, string2) {

return string1.length - string2.length;

};

 

// Declare and intitialize `myStringArray`

var myStringArray = ["abc", "a", "abcd", "ab", "gksutbs", "aerus"];

 

// Sort it

myStringArray.sort(compareStringLength);

 

// Log it to the console

console.log(myStringArray);

_____________________________________________________________________________________


Дата добавления: 2015-08-17; просмотров: 38 | Нарушение авторских прав


<== предыдущая страница | следующая страница ==>
УГАДАЙ ЧИСЛО С ПОДСКАЗКАМИ| Массив с четными и нечетными числами

mybiblioteka.su - 2015-2024 год. (0.007 сек.)