So i have made a web based program and I am using localStorage to save my variables. However I’m running into an issue where i cant get back the numbers from localStorage (as they are a string when saved) is there a way to set the strings back to a number without effecting the rest of the code?
let cardCount = 0;
let card = 0
function DisplayCardCount() {
cardCount++;
card++;
document.getElementById("DisplayCountCard").innerHTML = cardCount;
}
//Counting the cash
let cashCount = 0;
let cash = 0
function DisplayCashCount(){
//Display Session
cashCount++;
//Saving Data to local
cash++;
document.getElementById("DisplayCountCash").innerHTML = cashCount;
}
//Get Sell Total Price
let SellTotal = 0;
function DisplaySellTotal(){
SellTotal++;
document.getElementById("DisplaySellTotal").innerHTML = SellTotal*5;
return SellTotal;
}
//Clear all variables (set all varables back to 0)
function Clear(){
SellTotal = 0;
cashCount = 0;
cardCount = 0;
document.getElementById("DisplayCountCard").innerHTML = 0;
document.getElementById("DisplayCountCash").innerHTML = 0;
document.getElementById("DisplaySellTotal").innerHTML = 0;
}
//Save the payment information
let totalSales = 0
let totalCard = 0
let totalCash = 0
let totalSalesCount = 0
function takePayment(){
//Count the ammount of times Confirm has been pressed
let Counting = totalSales+=1;
//Save Array to local Storage
const SalesArray = [card, cash, Counting]
localStorage.setItem('Sales',JSON.stringify(SalesArray));
const SalesData = JSON.parse(localStorage.getItem('Sales'));
console.log(SalesData);
//Save Data to local storage for card and cash
localStorage.setItem('card',JSON(card))
localStorage.setItem('cash',JSON(cash))
//Set clear all functions to start again (not effecting local storage)
SellTotal = 0;
cashCount = 0;
cardCount = 0;
document.getElementById("DisplayCountCard").innerHTML = 0;
document.getElementById("DisplayCountCash").innerHTML = 0;
document.getElementById("DisplaySellTotal").innerHTML = 0;
}