Hello,

I am struggling with the output on this prompt generator, and I’ve tried to look up a solution and been unsuccessful so far. I honestly know nothing about coding other than what I’ve been learning in order to build perchance generators - so I know it may be something super simple I’m missing. Or I may have made it more complicated than it needs to be - or maybe what I want is something really complicated. I honestly don’t know. And I apologize if my lingo is awful!

The URL I’ve shared is an ultra-simplified version of the generator I am struggling with, and most of the list items have been eliminated so that what is left is guaranteed to duplicate the problem I’m having.

What I’m trying to accomplish with the current coding:

  1. That the generator defaults to 2 specific character names - Ed and Stede.
  2. That if a user inputs characters in the input box to customize their output that these two default characters do not show up. So not the user’s list + this default list being drawn from. Only the user’s list is drawn from if they input characters.
  3. That for certain output possibilities (line 1 for this simplified generator), whichever list is used is consumable so that a character’s name is not duplicated. For example, I would want “Ed can’t stop thinking about Stede,” not “Ed can’t stop thinking about Ed.” (I’ve attempted using [one] and [two] here.)

What is happening:

  1. The first time the page is loaded, or if it is refreshed, in the 1st line, where I’ve tried to use [one] and [two], it shows up as “undefined.” Once the generate button is clicked (and all subsequent clicks as long as the page is not refreshed), the output generates correctly.
  2. If I add custom characters in the user input box (let’s say “Jim” & “Olu”), on the first click of the generator button, only the 3rd line updates with these characters’ names. On the second click (and all subsequent clicks if the characters are left the same), all three lines show up with the correct characters.

So I would like it if I could figure out how to make it so that: a) the output loads correctly when the generator is first opened or immediately after the page is refreshed (no “undefined”) b) for the user input to show on all three lines once they’ve inputted their characters and clicked the generate button

Any help would be so greatly appreciated! Thank you for your time <3

  • wthit56@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    7 days ago

    The onclick takes JS code. The JS function called “update” updates the perchance stuff across the whole page. If you pass an element to the update function, it will only update that element.

    So in my test, I have an element with the id “output.” So just passing output to the update() function means I’m passing a reference to that element with the id “output.” And then only that element is updated.