2

For the most part, i got it all done. But when i refresh the page it does not save into the array and i cant find it, how do i make it so its not just a temp array and keep it in the website. Here is my code

const output = document.getElementById("joke")


var jokes = ["test123", "test1235", "testting 1"]

function inputJoke() {
    boxvalue = document.getElementById('box').value;
    jokes.push(boxvalue);
    console.log(jokes);
    return false;
  }

function randomChoice(){
    return jokes[Math.floor(Math.random() * jokes.length)]
    }

function jokeText(){
    output.innerHTML = `${randomChoice()}`
}

<div class="container">
    <h3>Douglas Dad Joke Generator</h3>
    <br>
    <br>
    <button id="jokeBtn" onclick="jokeText()" class="btn">Get Another Joke</button>
    <div class="text" id="joke"></div>

    <form onsubmit="return inputJoke()">
      <input class="submit" placeholder="Dad joke" type="text" id="box">
      <input class="submit" type="submit" value="Submit">
     </form>

  </div>

  <script src="script.js"></script>
  <link rel="stylesheet" href="style.css">

Here is the website https://dad.sscottdev.com

1 Answer 1

2

As it is, your jokes are stored in the code itself, or as we call it, hardcoded. If you wish for people to input and save their jokes you will have to add a small database and a small backend with it. I suggest you try looking for easy and simple ways for doing that like FastAPI(my recomendation), but in the end all you need is a remote database where all your jokes will be stored and can be retrieved from.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.