Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带循环javascript的报价生成器_Javascript - Fatal编程技术网

带循环javascript的报价生成器

带循环javascript的报价生成器,javascript,Javascript,我正在使用loop开发这个报价生成器。生成器必须从数组1+数组2+数组3返回一个随机引号(比如“爱”将是“你的任务”),但当它得到“和平”将是“你的开始”时,它必须发出警告:“你找到我了”。 我认为问题在于function select.quote不起作用 let array1 = [ " peace " , "love" , " money"]; let array2 = [ " will be " , "will never be ", "maybe will be"]; let array

我正在使用loop开发这个报价生成器。生成器必须从数组1+数组2+数组3返回一个随机引号(比如“爱”将是“你的任务”),但当它得到“和平”将是“你的开始”时,它必须发出警告:“你找到我了”。 我认为问题在于function select.quote不起作用

let array1 = [ " peace " , "love" , " money"];
let array2 = [ " will be " , "will never be ", "maybe will be"];
let array3 = [" your end", " your start", "your tasks"];

function finalQuote(...arrs) {
let quote = '';
for (let i = 0; i <arrs.length; i++) {
quote += arrs[i][Math.floor(Math.random() * 3)];{
return quote;}

select.quote = function(){
if (arrays){
if (array1 === 'peace', array2 === 'will be', array3 === 'your end'){
alert("you found me!");
}}else{
let FinalQuote =finalQuote(array1, array2, array3);}}

qt_btn.addEventListener("click", function(event) {
finalQuote();});
let array1=[“和平”、“爱情”、“金钱”];
让array2=[“将会”、“永远不会”、“可能会”];
让数组3=[“你的终点”、“你的起点”、“你的任务”];
函数最终引用(…arrs){
让我们引用=“”;

对于(让i=0;i可以做很多事情来整理代码,但是下面的内容应该可以工作,有很多方法可以解决这个问题

let array1 = [ "peace " , "love" , "money"];
let array2 = [ "will be " , "will never be ", "maybe will be"];
let array3 = ["your end", "your start", "your tasks"];

function checkStringForMatch (str, word) {
    return str.indexOf(word) !== -1
}

function finalQuote(...arrs) {
let quote = '';
    for (let i = 0; i < arrs.length; i++) {
        quote += arrs[i][Math.floor(Math.random() * 3)] + ' ';
    }
    if (checkStringForMatch(quote, 'peace') && checkStringForMatch(quote, 'will be') && checkStringForMatch(quote, 'your end')){
        alert("you found me!");
    } else {
        alert(quote)
    }
}

qt_btn.addEventListener("click", function(event) {
    finalQuote(array1, array2, array3);
});
let array1=[“和平”、“爱情”、“金钱”];
让array2=[“将会”、“永远不会”、“可能会”];
让数组3=[“你的终点”、“你的起点”、“你的任务”];
函数checkStringForMatch(str,word){
返回str.indexOf(word)!=-1
}
函数最终引用(…arrs){
让我们引用=“”;
for(设i=0;i
可以做很多事情来整理您的代码,但是下面的内容应该是可行的,有很多方法可以解决这个问题

let array1 = [ "peace " , "love" , "money"];
let array2 = [ "will be " , "will never be ", "maybe will be"];
let array3 = ["your end", "your start", "your tasks"];

function checkStringForMatch (str, word) {
    return str.indexOf(word) !== -1
}

function finalQuote(...arrs) {
let quote = '';
    for (let i = 0; i < arrs.length; i++) {
        quote += arrs[i][Math.floor(Math.random() * 3)] + ' ';
    }
    if (checkStringForMatch(quote, 'peace') && checkStringForMatch(quote, 'will be') && checkStringForMatch(quote, 'your end')){
        alert("you found me!");
    } else {
        alert(quote)
    }
}

qt_btn.addEventListener("click", function(event) {
    finalQuote(array1, array2, array3);
});
let array1=[“和平”、“爱情”、“金钱”];
让array2=[“将会”、“永远不会”、“可能会”];
让数组3=[“你的终点”、“你的起点”、“你的任务”];
函数checkStringForMatch(str,word){
返回str.indexOf(word)!=-1
}
函数最终引用(…arrs){
让我们引用=“”;
for(设i=0;i
欢迎使用SO。您没有提到实际问题是什么以及当前正在发生什么(与您认为应该发生的情况相比)。请详细说明,以便任何人都能提供帮助!嘿,对此表示抱歉。它应该随机返回数组1、数组2、数组3中的字符串(例如“love”将是“您的任务”),但当生成器生成“peace”时“将是”“您的开始”“。它必须提醒“您找到我了”。我认为问题在于循环。这是函数select.quote不起作用。我想问的是,现在发生了什么。您可能会收到什么错误消息。您面临什么问题?”不起作用"这可能意味着很多事情。你在浏览器控制台上得到了什么?我在控制台中有一个错误:未捕获引用错误:select未定义select.quote是什么?你是否在任何地方定义了select?为什么不在没有select.quote的情况下更改第二个函数,并给它一个与第一个类似的名称,然后从单击处理程序调用它,然后重新调用它将finalQuote()调用从handlerWelcome移到SO。您尚未提及实际问题以及当前正在发生的情况(与您认为应该发生的情况相比)。请详细说明,以便任何人都能提供帮助!嘿,对此表示抱歉。它应随机返回数组1、数组2、数组3中的字符串(例如“love”将是“您的任务”)但当生成器生成的“和平”将是“您的开始”时,它必须提醒“您找到了我”。我认为问题在于循环。不工作的是函数select.quote。这是可以理解的。我想问的是,现在发生了什么。您可能会收到什么错误消息。您面临什么问题?“不工作”这可能意味着很多事情。你在浏览器控制台上得到了什么?我在控制台中有一个错误:未捕获引用错误:select未定义select.quote是什么?你是否在任何地方定义了select?为什么不在没有select.quote的情况下更改第二个函数,并给它一个与第一个类似的名称,然后从单击处理程序调用它,然后重新调用它从处理程序中移动finalQuote()调用