Skip to content

Commit

Permalink
Add code for subtraction game
Browse files Browse the repository at this point in the history
  • Loading branch information
RoBizMan committed Mar 7, 2024
1 parent 042f77c commit a995fbc
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ function runGame(gameType) {
displayAdditionQuestion(num1, num2);
} else if (gameType === "multiply") {
displayMultiplyQuestion(num1, num2);
} else if (gameType === "subtract") {
displaySubtractQuestion(num1, num2);
} else {
alert(`Unknown game type: ${gameType}`);
throw `Unknown game type: ${gameType}. Aborting!`;
Expand Down Expand Up @@ -72,6 +74,8 @@ function calculateCorrectAnswer() {
return [operand1 + operand2, "addition"];
} else if (operator === "x") {
return [operand1 * operand2, "multiply"];
} else if (operator === "-") {
return [operand1 - operand2, "subtract"];
} else {
alert(`Unimplemented operator ${operator}`);
throw `Unimplemented operator ${operator}`;
Expand Down Expand Up @@ -105,7 +109,10 @@ function displayAdditionQuestion(operand1, operand2) {
document.getElementById('operator').textContent = "+";
}

function displaySubtractQuestion() {
function displaySubtractQuestion(operand1, operand2) {
document.getElementById('operand1').textContent = operand1 > operand2 ? operand1 : operand2;
document.getElementById('operand2').textContent = operand1 > operand2 ? operand2 : operand1;
document.getElementById('operator').textContent = "-";

}

Expand Down

0 comments on commit a995fbc

Please sign in to comment.