Completion requirements
View
2. Conditional Statements
2.2. An example on the use of if-else
Suppose that you are tasked to determine if a number is odd or even. The code structure below
provides a solution to this problem. (Note: Khub executes the window.alert statement in the code below)
- <script>
- x = 5
- if (x % 2 == 0){
- window.alert("The number is EVEN");
- }
- else{
- window.alert("The number is ODD");
- }
- </script>