gpt4 book ai didi

javascript - 为什么这段代码中的随机化不起作用?

转载 作者:行者123 更新时间:2023-12-03 06:32:08 25 4
gpt4 key购买 nike

感谢您回答我原来的问题,我之所以简单地编辑这篇文章来回答有关此代码的第二个问题,是因为该网站不允许我提出很多问题。我的问题是为什么 makejump1 不是随机真或假?它似乎总是成真。请帮助@Yhlas 和@codeConcussion

var isjumping1 = true;

while(isjumping1) {

var makesjump1 = Math.random()
if(makesjump1 => .51) {
makesjump1 = true }
else if(makesjump1 <= .50) {
makesjump1 = false }

var jump1 = prompt("Do you choose to JUMP, or let the fairies help you FLY").toUpperCase()
switch(jump1) {
case 'JUMP':
if(makesjump1 = true) {
console.log("You made the jump on your own, so the fairies reward you with a steel sword(9 DMG)")
damage = 9;
weapon = 'steel sword(9 DMG)'; }
else if(makesjump1 = false) {
console.log("You attempt the jump but miss it, and are hanging on by a thread")
console.log("The fairies rescue you, but you got scratched up, doing 3 damge to you.")
health = health - 3; }
isjumping1 = false;
break;
case 'FLY':
console.log("The fairies help you over the pit")
isjumping1 = false;
break;
default:
alert("That was not a choice!")
break; }
}

最佳答案

您在每个循环中将其分配为 true。使用 == 代替或只是...

while(isjumping1)

关于javascript - 为什么这段代码中的随机化不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38401428/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com