Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <meta charset="UTF-8">
- <body>
- <h1>My small program for learn JavaScript</h1>
- <link rel="stylesheet" type="text/css" media="screen" href="file:///D:/xxx.css" />
- <script type="text/javascript">
- //global variables
- var Title;
- var Hint;
- var rock;
- var paper;
- var scissors;
- var tie;
- var wins;
- var uChoice;
- var cChoice;
- function changeLang() {
- var lang = "";
- if (document.getElementById("lang") != null) {
- lang = document.getElementById("lang").value;
- } else {
- lang = "EN";
- }
- if (lang === "RU") {
- Title = "Игра камень, ножницы, бумага by Chemist";
- Hint = "Пожалуйста введите Ваш вариант (камень, ножницы или бумага):";
- rock = "камень";
- paper = "бумага";
- scissors = "ножницы";
- tie = "Ничья";
- wins = "победил вариант - ";
- uChoice = "Вы выбрали";
- cChoice = "Компьютер выбрал";
- } else {
- if (lang === "UK") {
- Title = "Гра камінь, ножиці, бумага by Chemist";
- Hint = "Будь-ласка оберіть Ваш варіант (каміть, ножиці чи бумага)";
- rock = "камінь";
- paper = "бумага";
- scissors = "ножиці";
- tie = "Нічия";
- wins = "переміг варіант - ";
- uChoice = "Ви обрали"
- cChoice = "Комп'ютер обрав";
- } else { //EN
- Title = "Game rock, scissors, paper by Chemist"
- Hint = "Please to choice Your variant (rock, scissors, paper)";
- rock = "rock";
- paper = "paper";
- scissors = "scissors";
- tie = "tie"
- wins = "wins - "
- uChoice = "You choice"
- cChoice = "Computer choice";
- }
- }
- document.getElementById("title1").innerHTML = Title;
- document.getElementById("hint1").innerHTML = Hint;
- document.getElementById("staff").options[0] = new Option(rock, rock);
- document.getElementById("staff").options[1] = new Option(scissors, scissors);
- document.getElementById("staff").options[2] = new Option(paper, paper);
- //console.log( document.getElementById("title1").innerHTML );
- }
- function calculate() {
- //get user Choice;
- //var userChoice = document.getElementById('myInput').value;
- var userChoice = document.getElementById("staff").value //selectedIndex;
- //document.write(uChoice + " " + userChoice + "<br>");
- document.getElementById("div1").innerHTML = uChoice + " " + userChoice + "<br>"
- var computerChoice = Math.random();
- if (computerChoice < (1.0/3.0)) {
- computerChoice = rock;
- } else if(computerChoice <= (2.0/3.0)) {
- computerChoice = paper;
- } else {
- computerChoice = scissors;
- }
- //console.log("Computer: " + computerChoice);
- //document.write(cChoice + " " + computerChoice + "<br>");
- document.getElementById("div2").innerHTML = cChoice + " " + computerChoice + "<br>"
- var compare = function (choice1, choice2) {
- if (choice1 == choice2) {
- return tie;
- } else {
- if (choice1 === rock) {
- if (choice2 === scissors) {
- return wins + rock;
- } else {
- return wins + paper;
- }
- } else {
- if (choice1 === paper) {
- if (choice2 === rock) {
- return wins + paper;
- } else {
- return wins + scissors;
- }
- } else { //choice1 === scissors
- if (choice2 === rock) {
- return wins + rock;
- } else {
- return wins + scissors;
- }
- }
- }
- }
- }
- //document.write( compare(userChoice, computerChoice) + "<br>");
- document.getElementById("div3").innerHTML = compare(userChoice, computerChoice) + "<br>";
- }
- </script>
- <select size="1" id="lang">
- <option selected value="EN">English</option>
- <option value="RU">Русский</option>
- <option value="UK">Українська</option>
- </select>
- <input type="button" onclick="changeLang()" value="Change"/><br>
- <h3><div id="title1"></div></h3><br>
- <div id="hint1"></div><br>
- <select size="1" id="staff">
- <option value="камень">камень</option>
- <option value="ножницы">ножницы</option>
- <option value="бумага">бумага</option>
- </select><br>
- <input type="button" onclick="calculate()" value="Calculate!"/><br><br>
- <div id="div1"></div>
- <div id="div2"></div>
- <div id="div3"></div>
- <br><br>
- <h3>end.</h3>
- <script type="text/javascript">
- changeLang();
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment