Hello everybody. I am trying to build a simple app which counts how many guests have entered the restaurant and then logs it put. I keep getting, wrong result. For example: 5+5= 55 instead of 10. Here is my javascript code:
let saveEl = document.getElementById("save-el")
let countEl = document.getElementById("count-el")
let totalEl = document.getElementById('total-el')
let count = 0
function increment() {
count += 1
countEl.textContent = count
}
function save() {
let separator = '-'
let countStr = `${count} ${separator}`;
saveEl.textContent += countStr;
let a = [countStr];
for(let i=0; i<a.length;i++){
a[i]= a + count;
}
totalEl.textContent = a;
countEl.textContent = 0
count = 0;
}
I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
if 5 + 5 answers 55 instead of 10 it must be string instead of integer
“5” + “5” = “55”
5 + 5 = 10
You should convert variable to integer or float first