Is there a method in Javascript, to load the page in-between prompts?

So I currently have JavaScript that asks for user prompts and inputs the data into a table, it’s a simple credit limit calculator. I know I can use something else like a button, but is there a way to pause and load in-between prompts? From testing I know loading separate javascript files will load in-between them, but is there another way?

Here’s a codepen link if anyone is interested, but I just want to know if I’m missing something, or if I just need to move onto another method here!

https://codepen.io/iskevinhome/pen/mdEvPbW

so are you trying to display the response in the div for [say] 3 seconds then show another prompt?

1 Like

So it initially asks for your credit limit and balance, and then will keep prompting you for balance changes until you reach the credit limit, in-between the balance change prompts, I’d like to have it update the HTML table. I don’t necessarily need a time limit in-between them, outside of how long it takes to update the table.

ok i see.

instead of creating a new table everytime, write a function that returns some divs and takes the table values as variables.

const createTable = (value) => {
    let table = <div>value</div> // create your table here
    return table
}

create a variable that updates after user submits required data

let creditLimit = 0;  // initialize variable

let input = (() => {
    return +prompt("whats your credit limit?") /// plus sign in front (+prompt) converts string to float or number
})() // self executing function 

const updateCreditLimit = (value) => {
    creditLimit +=  value
}

then enter the value of createTable into the div that you want it.

updateCreditLimit(input)
document.querySelector('#tableDiv').innerHTML = createTable(creditLimit)

everytime the function runs it will return the table with the updated values

1 Like