Update calculator.js
This commit is contained in:
		
							parent
							
								
									edab9ba9c6
								
							
						
					
					
						commit
						edf90a4f6c
					
				| 
						 | 
					@ -74,6 +74,9 @@ const operate = function(op, num1, num2) {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
function updateDisplay(id) {
 | 
					function updateDisplay(id) {
 | 
				
			||||||
 | 
					  if (display.textContent === "To infinity, and beyond!") {
 | 
				
			||||||
 | 
					    display.textContent = id;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  switch (id) {
 | 
					  switch (id) {
 | 
				
			||||||
    case '!':
 | 
					    case '!':
 | 
				
			||||||
      operator = id;
 | 
					      operator = id;
 | 
				
			||||||
| 
						 | 
					@ -95,10 +98,8 @@ function updateDisplay(id) {
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      if (includesSpec) {
 | 
					      if (includesSpec) {
 | 
				
			||||||
        let num2 = display.textContent.split(/[\/+^!-*-]/);
 | 
					        let num2 = display.textContent.split(/[\/+^!-*-]/);
 | 
				
			||||||
        num1 = num2[0];
 | 
					        num1 = parseFloat(num2[0]);
 | 
				
			||||||
        num1 = parseFloat(num1);
 | 
					        num2 = parseFloat(num2[1]);
 | 
				
			||||||
        num2 = num2[1];
 | 
					 | 
				
			||||||
        num2 = parseFloat(num2);
 | 
					 | 
				
			||||||
        let currentAnswer = operate(operator, num1, num2);
 | 
					        let currentAnswer = operate(operator, num1, num2);
 | 
				
			||||||
        operator = id;
 | 
					        operator = id;
 | 
				
			||||||
        display.textContent = currentAnswer + id;
 | 
					        display.textContent = currentAnswer + id;
 | 
				
			||||||
| 
						 | 
					@ -125,7 +126,6 @@ function updateDisplay(id) {
 | 
				
			||||||
    case '9':
 | 
					    case '9':
 | 
				
			||||||
    case '0':
 | 
					    case '0':
 | 
				
			||||||
      if (displayValue === 0) {
 | 
					      if (displayValue === 0) {
 | 
				
			||||||
        display.textContent = '';
 | 
					 | 
				
			||||||
        display.textContent = id;
 | 
					        display.textContent = id;
 | 
				
			||||||
        displayValue = display.textContent;
 | 
					        displayValue = display.textContent;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
| 
						 | 
					@ -144,14 +144,14 @@ function updateDisplay(id) {
 | 
				
			||||||
      if (!num2[1]) {
 | 
					      if (!num2[1]) {
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      num1 = num2[0];
 | 
					      num1 = parseFloat(num2[0]);
 | 
				
			||||||
      num1 = parseFloat(num1);
 | 
					      num2 = parseFloat(num2[1]);
 | 
				
			||||||
      num2 = num2[1];
 | 
					 | 
				
			||||||
      num2 = parseFloat(num2);
 | 
					 | 
				
			||||||
      answer = operate(operator, num1, num2)
 | 
					      answer = operate(operator, num1, num2)
 | 
				
			||||||
      if (answer === Infinity) {
 | 
					      if (answer === Infinity) {
 | 
				
			||||||
        display.style.fontSize = '40px';
 | 
					        display.style.fontSize = '40px';
 | 
				
			||||||
        display.textContent = 'To infinity, and beyond!';
 | 
					        display.textContent = 'To infinity, and beyond!';
 | 
				
			||||||
 | 
					        answer = 0;
 | 
				
			||||||
 | 
					        displayValue = 0;
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      display.textContent = answer;
 | 
					      display.textContent = answer;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue