The page doesn't refresh . Why?
I tried to build this JavaScript calculator, but there is a problem. When I enter values it's working well, but the problem is when I refresh the page, it doesn't refresh; it only saves the first values that were entered. Why?
var
displayResultBtn = document.querySelector('#calc-btn'),
backToInputBtn = document.querySelector('#back-input');
var
inputPage = document.querySelector('#data-inputs'),
outputPage = document.querySelector('#data-outputs');
/* ========== Go to Result ========== */
displayResultBtn.addEventListener('click', displayResult);
function displayResult(){
var
coutJour = parseFloat(document.querySelector('#cj-input').value),
nbrJour = parseInt(document.querySelector('#nj-input').value),
prime;
// calcul Base Salary
slrBase = coutJour * nbrJour;
if(nbrJour>=25){
prime = 200;
}
else if(nbrJour>=20){
prime = 150;
}
else if(nbrJour>=15){
prime = 100;
}
else if(nbrJour<15){
prime = 50;
}
//calcul Net Salary
var slrNet = slrBase + prime;
//display results in his places
document.querySelector('#slrBase-result').innerHTML = slrBase + " $";
document.querySelector('#prime-result').innerHTML = prime + " $";
document.querySelector('#slrNet-result').innerHTML = slrNet + " $",
document.querySelector('#slrNet-result').style.color = "red";
// display the result Page
inputPage.style.display = "none";
outputPage.style.display = "flex";
}
/* ========== Back to inputs ========== */
backToInputBtn.addEventListener('click', displayInputs);
function displayInputs(){
outputPage.style.display = "none";
inputPage.style.display = "initial";
}
*{
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: sans-serif;
}
body{
width: 100%;
height: 100vh;
display: grid;
grid-template-rows: 10% 85% 5%;
}
/* ========== Header ========== */
header{
width: 100%;
display: flex;
justify-content: center;
align-items: center;
background-color: #a52a2a;
}
header h1{
font-size: 2.5rem;
font-weight: 600;
text-transform: uppercase;
letter-spacing: .05rem;
color: #fff;
}
main{
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
/* ========== Input ========== */
#data-inputs{
display: initial;
width: 300px;
height: auto;
padding: 25px;
}
.inputs{
margin-bottom: 25px;
}
input{
width: 100%;
margin-bottom: 15px;
padding: 5px;
outline: none;
border: none;
border-bottom: 1px solid;
font-size: 1rem;
text-align: center;
background-color: transparent;
}
input::placeholder{
font-size: 1rem;
text-align: center;
}
input:focus{
border-bottom: 2px solid #a52a2a;
}
.btns{
width: 100%;
display: flex;
justify-content: space-between;
}
button{
padding: 10px;
outline: none;
font-size: 1rem;
font-weight: 600;
text-transform: uppercase;
cursor: pointer;
transition: .3s;
}
button:hover{
transform: translateY(-2px);
box-shadow: 0 2px 4px #333333;
}
#calc-btn, .final__btn{
width: 50%;
border: none;
color: #fff;
background-color: #a52a2a;
}
#reset-btn{
width: 45%;
border: 1px solid #a52a2a;
color: #a52a2a;
background-color: transparent;
}
/* ========== Output ========== */
#data-outputs{
width: 400px;
height: auto;
display: none;
flex-direction: column;
row-gap: 2rem;
padding: 25px;
}
.outputs{
background-color: #a52a2a;
}
.result__container{
display: flex;
justify-content: space-between;
margin: 2px;
padding: 10px;
font-size: 1.2rem;
font-weight: 500;
background-color: #fff;
}
.btn{
width: 100%;
display: flex;
justify-content: center;
}
/* ========== Footer ========== */
footer{
display: flex;
justify-content: center;
align-items: center;
color: #fff;
background-color: #a52a2a;
}
Net Salary
Base Salary :
0 $
Prime :
0 $
Net Salary :
0 $