【发布时间】:2019-04-10 19:25:15
【问题描述】:
我正在制作一个文本“游戏”,它有 3 个玩家,他们的名字在一个数组中,我正在尝试设置一个分数计数,以便每次按下按钮后随机生成他们的名字,它被添加到他们的个人分数中。
由于这是我的第一个项目,我在任何方法上都没有取得任何成功。
var playerOne = prompt("Enter the name of the 1st player");
var playerTwo = prompt("Enter the name of the 2nd player");
var playerThree = prompt("Enter the name of the 3rd player");
const playerName = [playerOne, playerTwo, playerThree];
const didHow = ['quietly', 'carefully', 'slowly', 'quickly', 'secretly', 'ragefully'];
const didWhat = ['went', 'ran', 'fell', 'drove', 'jumped', 'fought', 'died'];
const quoteBtn = document.querySelector('#quoteBtn');
const playerNameQ = document.querySelector('#playerName');
const didHowQ = document.querySelector('#didHow');
const didWhatQ = document.querySelector('#didWhat');
quoteBtn.addEventListener('click', displayQuote);
function displayQuote() {
let numberOne = Math.floor(Math.random()*playerName.length);
let numberTwo = Math.floor(Math.random()*didHow.length);
let numberThree = Math.floor(Math.random()*didWhat.length);
playerNameQ.innerHTML = playerName[numberOne];
didHowQ.innerHTML = didHow[numberTwo];
didWhatQ.innerHTML = didWhat[numberThree];
}
【问题讨论】:
-
那么当用户输入他们的名字时,将他们的分数设置为-1?更具体地说明你想要什么。你得到什么错误?你面临什么问题?
标签: javascript