Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion src/branching_logic/challenges.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,38 @@ if the number is odd.

## Challenge 3

What will this program output when run? Write down your guess and then try running it.

```java,editable
void main() {
int num = 10;

if (num > 1)
IO.println("It is greater than 1");
if (num > 5)
IO.println("It is greater than 5");
}
```
<details>
<summary> Hint 1: </summary>
<p>Else if statements only execute if previous condition is false.</p>
</details>

<details>
<summary> Hint 2: </summary>
<p>If statements always execute.</p>
</details>

<details>
<summary> Solution </summary>
<p><pre>
It is greater than 1
It is greater than 5
</pre></p>
</details>

## Challenge 4

Write code that will output `allowed` if the the `password` variable is equal to
`"abc123"` and `not allowed` if it isn't.

Expand All @@ -39,7 +71,7 @@ void main() {
}
```

## Challenge 4
## Challenge 5

Write code that will assign the string `The number {x} is even` to `message` if `x` is an even number
and `The number {x} is odd` if `x` is an odd number.
Expand Down