Just starting out with learning Typescript and tackling this challenge from Execute Program:
Create a function that either adds or subtracts 1 from a given number. The first argument is the number, and the second argument is a boolean. If the boolean is true, add 1; otherwise, subtract 1.
I've attempted various versions of the code below:
function addOrSubtract(x: number, y: boolean): any {
if (y = true) {
return x+1;
} else {
return x-1;
}
return x;
}
addOrSubtract(5, true);
addOrSubtract(5, false);
The problem I'm facing is that the test only recognizes the first condition. Even adding an additional else if (y = false)
statement yields the same outcome.
Thank you in advance