gpt4 book ai didi

javascript - 我在使用一些 javascript do while 循环时遇到问题

转载 作者:行者123 更新时间:2023-11-28 15:31:34 24 4
gpt4 key购买 nike

我正在编写一个代码猜测程序来测试某些 iPhone 密码的安全性(这与任何非法行为没有任何关系或用于闯入实际的 iPhone)。 do/while 循环一旦发生就会结束所有响应,并且最后两行不会打印到控制台。

print("Hi!");
print("I am a password security tester.");

var tries = 0

var guess1 = 0
var guess2 = 0
var guess3 = 0
var guess4 = 0

var guess = (guess1 * 1000) + (guess2 * 100) + (guess3 * 10) + guess4;

var password1 = (Math.floor(Math.random()*9));
var password2 = (Math.floor(Math.random()*9));
var password3 = (Math.floor(Math.random()*9));
var password4 = (Math.floor(Math.random()*9));

var password = (password1 * 1000) + (password2 * 100) + (password3 * 10) + password4;

print("This is the randomly genorated password: " + password);
print("And now begins the guessing");

do{
guess1 + 1;
tries + 1;
}while (password1 != guess1);

do{
guess2 + 1;
tries + 1;
}while (password2 != guess2);

do{
guess3 + 1;
tries + 1;
}while (password3 != guess3);

do{
guess4 + 1;
tries + 1;
}while (password4 != guess4);

print("Complete in " + tries + " tries");
print("The answer is: " + guess);

最佳答案

Jacob Ewing's answer是正确的,但另一个问题是 guess 最后仍然是 0,因为它不会自动更新。您需要执行以下操作:

var guess = (guess1 * 1000) + (guess2 * 100) + (guess3 * 10) + guess4;

之前:

print("Complete in " + tries + " tries");
print("The answer is: " + guess);

关于javascript - 我在使用一些 javascript do while 循环时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27157878/

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