Ian_Miller
Ian_Miller

Reputation: 79

quotation generator Javascript

I have to create a quote generator. It has to generate randomly the quotes. Each quote is a combination of 3 sentences. Once it gets for example "peace" "will be" "your start" it has to alert "FOUND".

I started to code this but it is not working.

let qt_btn = document.getElementById('qt_btn');

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;}


let FinalQuote =finalQuote(array1, array2, array3);


qt_btn.addEventListener("click", function(event) {



finalQuote();



});

Thank you

Upvotes: 1

Views: 61

Answers (1)

Mos&#232; Raguzzini
Mos&#232; Raguzzini

Reputation: 15851

you forgot to pass the argument to your method, check my snippet:

let qt_btn = document.getElementById('qt_btn');

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;}


let FinalQuote =finalQuote(array1, array2, array3);


qt_btn.addEventListener("click", function(event) {



console.log(finalQuote(array1, array2, array3));



});
<button id="qt_btn">quote</button>

Upvotes: 1

Related Questions