JSFiddle - React, Tailwind, and code Playground
JavaScript
// Declare input and a new array
let input = undefined;
const arr = [];
while (input !== 'done') {
// Get the input
input = prompt('Enter some text');
// If input is not `done` push the input
// to the array
if (input !== 'done') arr.push(input);
}
// If the array has some elements
// In your working code remove this line, and
// uncomment out the next
// if (arr.length) console.log(JSON.stringify(arr));
if (arr.length) saveData(arr);
function saveData(arr) {
localStorage.setItem('data', JSON.stringify(arr));
}