它的代码有什么问题说“你赢了! - 解决了 [英] What is wrong with my code it keeps says "you win! - Solved
本文介绍了它的代码有什么问题说“你赢了! - 解决了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var rock = "rock";
var paper = "paper";
var computerPick = null;
var d = Math.random() * 100
var sizzors = "Sizzors";
var pick = prompt("Please pick rock, paper or sizzors", "<Answer here>");
if(pick = "sizzors") {
if( d < 33) {
computerPick = "sizzors"
}
else if(d < 66){
computerPick = "rock"
}
else{
computerPick = "paper"
};
if(computerPick = "paper"){
console.log("You Win!(they picked paper)")
}else if(computerPick = "rock"){
console.log("You Lost(They picked rock)")
}else{
console.log("It was a tie!(They picked sizzors)")
};
} else if(pick = "paper"){
if( d < 33) {
computerPick = "sizzors"
}
else if(d < 66){
computerPick = "rock"
}
else{
computerPick = "paper"
};
if(computerPick = "paper"){
console.log("It was a tie!(They picked paper)")
}else if(computerPick = "rock"){
console.log("You Won!(They picked rock)")
}else{
console.log("You Lost!(They picked sizzors)")
};
}else if(pick = "rock"){
if( d < 33) {
computerPick = "sizzors"
}
else if(d < 66){
computerPick = "rock"
}
else{
computerPick = "paper"
};
if(computerPick = "paper"){
console.log("You Lost!(They pickedpaper)")
}else if(computerPick = "rock"){
console.log("It was a tie!(They picked rock)")
}else{
console.log("You Won!(They picked sizzors)")
};
}else{
console.log("You didnt pick rock paper or sizzors!")
}
我尝试了什么:
我无法弄清楚它有什么问题!
What I have tried:
I cant figure out whats wrong with it!
推荐答案
我已经弄清楚了我不再需要帮助了!
I have figured it out i dont need help anymore!
你的代码比标题中的代码有更多问题。
这个代码以一种微妙的方式错误:
Your code have more problems than the one in title.
This code is wrong in a subtile way:
var d = Math.random() * 100
...
if( d < 33) {
computerPick = "sizzors"
}
else if(d < 66){
computerPick = "rock"
}
else{
computerPick = "paper"
};
赔率为:
-sizzors 33%
-rock 33%
-paper 34%
此代码更好:
Odds are:
-sizzors 33%
-rock 33%
-paper 34%
This code is better:
var d = Math.random() * 3
...
if( d < 1) {
computerPick = "sizzors"
}
else if(d < 2){
computerPick = "rock"
}
else{
computerPick = "paper"
};
这篇关于它的代码有什么问题说“你赢了! - 解决了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文