0
我似乎无法弄清楚为什么我不能计算积分,并保持它们为每个用户总数..任何建议?请帮忙。我能够使用提示等。但是,试图将其带到生活在浏览器一直是个挑战,以建立这个游戏..难以计算总数Javascript
下面是代码:
function getName() {
var name = document.getElementById('fName').value;
// console.log(name);
$(".greetingPlayer").append("<h3 class='greeting'>Greetings " + name + "!</h3><br><h4>Please choose from the following Weapons...</h4>");
$(".statsA").css("display", "none");
}
var userChoice;
function choices(weapon) {
userChoice = weapon;
// console.log(userChoice);
$(".greetingPlayer").append("<h4 class='userChoice'>Users Choice : " + userChoice + "!</h4>");
var computerChoice = Math.random();
if (computerChoice <= 0.34) {
computerChoice = "rock";
} else if (computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
// console.log(computerChoice);
$(".greetingPlayer").append("<h4 class='computerChoice'>Computers Choice : " + computerChoice + "!</h4>");
function compare(choice1, choice2) {
var playing = true;
var human = 0;
var comp = 0;
while (playing) {
if (choice1 === choice2) {
console.log("The result is a tie!");
human = score;
comp = score;
} else if (choice1 === "rock") {
if (choice2 === "scissors") {
console.log("rock wins!");
} else {
console.log("paper wins!");
}
} else if (choice1 === "paper") {
if (choice2 === "rock") {
console.log("paper wins!");
} else {
console.log("scissors wins!");
}
} else if (choice1 === "scissors") {
if (choice2 === "paper") {
console.log("scissors wins!");
} else {
console.log("rock wins!");
}
} else {
console.log("That's not an option! Do it over " + name + " and try again!");
}
playing = false;
}
console.log("human : " + human);
console.log("comp : " + comp);
var numpoints = 0;
function points() {
if (++score >= str.length) {
numpoints++;
document.getElementByClassName("points").textContent = "Score: " + numpoints;
}
}
}
compare(userChoice, computerChoice);
}
// $(".greetingPlayer").append("<h4 class='userWeapon'> " + name + "! You win!</h4>");
您的代码没有意义。为什么你将得分与一个甚至没有初始化的str变量进行比较?另外,你永远不会打电话给积分功能,所以我不知道你的分数应该如何更新。 – QuantumLicht 2014-12-07 23:11:50