I dont understand the order

I’ve sadly tried about 40 different ways, iteration through the array, moving variables around, I got it to work once but then the button only works once. why doesn’t this work, why wouldn’t length be defined??? I understand scope but what order do these things go in? how do i learn this?

(https://codepen.io/ryan-marie/pen/poNjPvz?editors=1010)

`

Currently your quoteMachine function doesn’t have a body, so it won’t do anything.

? doesn’t have a body?
is the Math.floor() not a body?

When you shared your codepen, it just said function quoteMachine(). Now it appears that you have completely commented out your quoteMachine function.

Why don’t you share what you think your JavaScript code should be here, as formatted code.

i just get frustrated… and then I ask on this forum and it doesn’t help. thanks anyway.

it’s difficult to help if the code you ask for help about is not the one people can see

can you post the code, or say that the code you need help with is the in the pen and you are not going to change it for a bit?

I commented out what I was attempting because well, I want to understand why my every attempt has failed. here is my latest attempt which returns quoteMachine is not defined !!!???

function quoteMachine() {
  for(let i = 0; i < quotes.length; i++){
    newquote = quotes[i][0];
    
  }return newQuote;
};

document.getElementById('text')innerHTML = newQuote;
function quoteMachine(){
  let quote = quotes[Math.floor(Math.random() * quotes.length)];
  return quote;
  
};


document.getElementById('text').innerHTML = quote;

this returns length undefined !? quotes may have been passed in as an argument.

I would expect newquote is not defined or newQuote is not defined

if you add "use strict" (exactly like that, quotes included) on the first line of your javascript editor you could get more errors

function quoteMachine(){
  for(let n of quotes){
    document.getElementById('text').innerHTML = n[0];
    document.getElementById('author').innerHTML =n[1];
    
  }
};


this pushes the last index in and the button stops responding.

im not using use strict,
i tried let newQuote = quotes[i]
i get the same error

you also need the line that changes the html inside the function, if you want it to do something to your html

This will replace the contents of those elements with every one of the quotes in order and then stop on the last one. This is going to be fast enough that it won’t actually redraw the page for every one, and you’ll only see the final quote. It’s not that the button isn’t responding; it’s just that it does the same thing every time.

function quoteMachine() {
  for(let i = 0; i < quotes.length; i++){
    let newQuote = quotes[i][0];
    document.getElementById("text")innerHTML = newQuote;
  
  }
};

This is one of the many things ive tried: im still getting quoteMachine is undefined?

this is a syntax error - you are missing a character

Where are you seeing “quoteMachine is undefined”? You should be getting a different error. Probably something about an unexpected identifier.

omg thank you. That works but why only once?
I mean once as in i cannot keep clicking and get new quotes.

You don’t have any randomization, so it will always do the exact same thing. In this case it will go through all of the quotes in order and when the loop is done running newQuote will always be the last quote.

I tried using Math.floor() but i dont understand the order of things. where to plug in i guess.

I already commented that

try to see the similar parts and the different parts in what works without error but still does not do what you want