Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- window.alert('コンピュータとジャンケンで対戦します');
- let win = 0;
- let draw = 0;
- let lose = 0;
- for (let i = 1; i <= 10; i++) {
- const youStr = window.prompt('グー・チョキ・パーのいずれかを入力して下さい');
- let you;
- if (youStr == 'グー') {
- you = 0;
- } else if (youStr == 'チョキ') {
- you = 1;
- } else if (youStr == 'パー') {
- you = 2;
- } else {
- window.alert('文字列を正しく入力して下さい');
- continue;
- }
- const cpu = Math.floor(Math.random() * 3);
- let cpuStr;
- if (cpu === 0) {
- cpuStr = 'グー';
- } else if (cpu === 1) {
- cpuStr = 'チョキ';
- } else /* cpu === 2*/ {
- cpuStr = 'パー';
- }
- window.alert('あなたは' + youStr + '、コンピュータは' + cpuStr + 'です');
- if ((you === 0 && cpu === 1) || (you === 1 && cpu === 2) || (you === 2 && cpu === 0)) {
- window.alert('あなたの勝ちです!');
- win++;
- } else if (you === cpu) {
- window.alert('あいこです!');
- draw++;
- } else {
- window.alert('コンピュータの勝ちです!');
- lose++;
- }
- const next = window.confirm('続けますか?');
- if (!next) {
- break;
- }
- }
- window.alert('あなたは' + win + '勝' + lose + '敗' + draw + '引き分けでした');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement