Hi everyone,
I started working on the JS calculator today and I am running into a weird issue.
you can find the codepen here:
https://codepen.io/heenslice/pen/YxOdaM?editors=0010
I am currently attempting to to console.log the correct answers before displaying results to the screen.
My current issue is regarding this section.
// display numbers (first number)
$('.number').click(function(){
var $buttonValue = $(this).text();
totalString1 = totalString1 + $buttonValue;
console.log(totalString1);
return totalString1;
});
// apply operator
$('.operator').click(function(){
$('.btn').addClass('number2');
$('.btn').removeClass('number');
if($(this).text() === '+'){
console.log('add');
}
});
// display numbers (second number)
$('.number2').click(function(){
console.log('2nd function');
var $buttonValue = $(this).text();
totalString2 = totalString2 + $buttonValue;
console.log(totalString2);
return totalString2;
});
My logic is that after you create the first string and click on ‘+’. It will remove the number class. and add the number2 class. So the next time you click a number we will start creating the second string.
However, even after removing the number class. When I click a number it still fires the first function. Am I missing something really obvious?
Any help/advice would be much appreciated