# Front End Development Libraries Projects - Build a JavaScript Calculator

hello guys so i have a problem with 2 test 12 and 16

but the code i seem to have wrong is somewhere in here

``````function equ(){
display = document.getElementById("display").innerHTML
for(let i = 0; i < display.length; i++){
counter++;
switch(display[i]){

case "+":
if(number === 0){
number = display.slice(0,i);
};
number1 = display.slice(i+1,i+counter);
result = +number + +number1;
number= result;
break;

case "*":
if(number === 0){
number = display.slice(0,i);
}
number1 = display.slice(i+1,i+2);
result = +number * +number1;
number= result;
break;

case "-":
if(number === 0){
number = display.slice(0,i);
}
number1 = display.slice(i+1,i+2);
console.log(number, number1);
result = +number - +number1;
number = result;
break;

case "/":
if(number === 0){
number = display.slice(0,i);
};
number1 = display.slice(i+1,i+(counter+1));
result = +number / +number1;
number= result;
break;
}
}
document.getElementById("display").innerHTML = result;
number = 0;
counter = 0;
};```

this is my codepen [https://codepen.io/codeMour/pen/jOpWpgM](https://codepen.io/codeMour/pen/jOpWpgM)``````

You need to do some logging to see what your code is doing. For instance in the multiplication:

``````      case "*":
if (number === 0) {
number = display.slice(0, i);
}
number1 = display.slice(i + 1, i + 2);
console.log(`number: \${number} number1: \${number1}`);
result = +number * +number1;
number = result;
break;
``````

The logging of the numbers yields interesting results. I would proceed similarly with the subtraction.

changes the code all good expect test 16 i will look at it tommorow

just finished it thanks for the hint your console.log was amazing

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.