Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if a number is even using bitwise AND.
DSA Typescript
function isEven(num: number): boolean {
return (num [1] 1) === 0;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise OR '|' instead of AND '&'.
Using XOR '^' which does not check evenness.
Using right shift '>>' which shifts bits instead of checking.
✗ Incorrect
The bitwise AND operator '&' with 1 checks the least significant bit. If it is 0, the number is even.
2fill in blank
mediumComplete the code to check if a number is odd using bitwise operation.
DSA Typescript
function isOdd(num: number): boolean {
return (num [1] 1) === 1;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise OR '|' which does not isolate the least significant bit.
Using XOR '^' which toggles bits.
Using right shift '>>' which shifts bits instead of checking.
✗ Incorrect
Using bitwise AND '&' with 1 checks if the least significant bit is 1, which means the number is odd.
3fill in blank
hardFix the error in the function to correctly return true if number is even.
DSA Typescript
function checkEven(num: number): boolean {
if ((num [1] 1) == 1) {
return false;
}
return true;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise OR '|' which does not isolate the bit.
Using XOR '^' which toggles bits.
Using right shift '>>' which shifts bits instead of checking.
✗ Incorrect
The bitwise AND '&' with 1 checks the least significant bit. If it is 1, the number is odd, so return false; otherwise true.
4fill in blank
hardFill both blanks to create a function that returns 'Even' or 'Odd' using bitwise check.
DSA Typescript
function evenOrOdd(num: number): string {
if ((num [1] 1) === [2]) {
return 'Odd';
}
return 'Even';
}Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise OR '|' instead of AND '&'.
Comparing to 0 instead of 1 for odd check.
✗ Incorrect
Use bitwise AND '&' with 1 to check the least significant bit. If it equals 1, the number is odd.
5fill in blank
hardFill all three blanks to create a function that returns true if number is odd, false if even, using bitwise operators.
DSA Typescript
function isNumberOdd(num: number): boolean {
return (num [1] [2]) === [3];
}Attempts:
3 left
💡 Hint
Common Mistakes
Using bitwise OR '|' which does not isolate the bit.
Comparing to 0 instead of 1 for odd check.
✗ Incorrect
Use bitwise AND '&' with 1 and compare to 1 to check if number is odd.
