Session Storage P1
by Alex Cowan
HTML
<div class="input-container">
<label for="input1">Value 1:</label>
<input type="text" id="input1" class="shared-class">
</div>
<div class="input-container">
<label for="input2">Value 2:</label>
<input type="text" id="input2" class="shared-class">
</div>
<button id="submit-button">Submit</button>
CSS
.input-container {
margin-bottom: 10px;
}
JavaScript
document.addEventListener("DOMContentLoaded", function() {
//add listener for user input
document.getElementById('submit-button').addEventListener('click', logTotal);
});
function calculateTotal() {
var value1 = parseFloat(document.getElementById('input1').value) || 0;
var value2 = parseFloat(document.getElementById('input2').value) || 0;
var total = value1 + value2;
localStorage.setItem("aTotal", total);
}
function logTotal() {
calculateTotal();
var theirTotal = localStorage.getItem("aTotal");
console.log("Total: ", theirTotal);
}