var s = 0;
btn.addEventListener('click', function() {
var ModelMake = prompt("Enter The Model Make"),
ModelYear = prompt("Enter The Model Year"),
Km = prompt("Enter The Amount Of Km"),
Price = prompt("Enter The Price"),
Status = prompt("Enter The Car's Status"),
FinalPrice,
Details = prompt("Enter the Details");
localStorage.setItem(s += 1, JSON.stringify({
ModelMake: ModelMake,
ModelYear: ModelYear,
Km: Km,
Price: Price,
Status: Status,
Details: Details,
FinalPrice: FinalPrice
}));
How do i avoid having my previous localStorage objects overwritten after the user REFRESHES or CLOSES the browser. The reason i capitalized is to emphasize that this code works and keeps generating different objects by incrementing as long as the user doesn't refresh or close the browser. the moment you refresh or reopen the application then enter new values the previous objects get overwritten with the new ones and the incrementation starts all over from 1 (overwriting the previous 1).