loop exercise
This commit is contained in:
parent
6f0ddc2595
commit
96de810c75
@ -40,13 +40,13 @@ function keyTyped() {
|
||||
### 📚 Exercice
|
||||
|
||||
1. Modify sketch 2.0 so that:
|
||||
* When key 'k' is pressed then "Hi Karin!" is printed on the console
|
||||
* When key 's' is pressed then "Hi Sigrid!" is printed on the console
|
||||
* When key 'n' is pressed then "Hi Nanna!" is printed on the console
|
||||
* When key 'm' is pressed then "Hi Maaike!" is printed on the console
|
||||
* When key 'k' is typed then "Hi Karin!" is printed on the console
|
||||
* When key 's' is typed then "Hi Sigrid!" is printed on the console
|
||||
* When key 'n' is typed then "Hi Nanna!" is printed on the console
|
||||
* When key 'm' is typed then "Hi Maaike!" is printed on the console
|
||||
|
||||
2. Modify sketch 2.0 so that:
|
||||
* Every time key 'x' is pressed then print the name of the following person in the array ("Hi David!", "Hi Karin!", "Hi Sigrid!", and so forth)
|
||||
* Every time key 'x' is typed then print the name of the following person in the array ("Hi David!", "Hi Karin!", "Hi Sigrid!", and so forth)
|
||||
|
||||
### 🤔 Who/what is "undefined"?
|
||||
|
||||
@ -73,7 +73,7 @@ function draw() {
|
||||
|
||||
function keyTyped() {
|
||||
if(key == 'x') {
|
||||
for(let i = 0; i < 4; i++) {
|
||||
for(let i = 0; i < ACTIVITIES.length; i++) {
|
||||
print(NAMES[INDEX] + " likes to play " + ACTIVITIES[i]);
|
||||
}
|
||||
}
|
||||
@ -96,10 +96,30 @@ let i = 0
|
||||
// is the declaration and initialisation of the control variable (i)
|
||||
|
||||
i < X
|
||||
//is the continuation condition: if the condition is true, then executed the statement in the loop [do_something();], exit the loop when the consition is false
|
||||
//is the loop continuation condition: if the condition is true, the statement in the loop [do_something();] is executed, otherwise exit the loop when the condition is false
|
||||
|
||||
i++
|
||||
//is the incremental (update) statement that is executed at the end of the loop (i.e. after the loop statement [do_something();] as been executed)
|
||||
//is the incremental (update) statement that is executed at the end of the loop (i.e. just after the loop statement [do_something();] as been executed)
|
||||
```
|
||||
|
||||
### 📚 Exercice
|
||||
|
||||
1. Modify skecth 2.1 so that every one listed in the NAMES array have all the activities listed in the ACTIVITIES array be printed out on the console when key 'x' is typed. The console output should look something like:
|
||||
|
||||
```
|
||||
Karin likes to play piano
|
||||
Karin likes to play tennis
|
||||
Karin likes to play chess
|
||||
Karin likes to play records
|
||||
Sigrid likes to play piano
|
||||
Sigrid likes to play tennis
|
||||
Sigrid likes to play chess
|
||||
Sigrid likes to play records
|
||||
Nanna likes to play piano
|
||||
Nanna likes to play tennis
|
||||
Nanna likes to play chess
|
||||
(etc.)
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user