Skip to content

Commit

Permalink
Quiz tab (#810)
Browse files Browse the repository at this point in the history
* First approximation to quizzes in tabs.

* Maintain iframes but clean up X-Frame header setting and templates to be used inside the iframe.

* Add required field to yaml

* Do not hide blue top bar when showing quiz tab, only the name input & buttons.

* Unorthodox CSS for quiz iframe.

* updates nl.yaml for the quiz
  • Loading branch information
fpereiro authored Sep 27, 2021
1 parent 31ae185 commit 3ee401f
Show file tree
Hide file tree
Showing 16 changed files with 298 additions and 1,379 deletions.
8 changes: 6 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ def load_adventures_per_level(lang, level):
for short_name, adventure in adventures.items ():
if not level in adventure['levels']:
continue
# end adventure is the quiz
# if quizzes are not enabled, do not load it
if short_name == 'end' and not config['quiz-enabled']:
continue
all_adventures.append({
'short_name': short_name,
'name': adventure['name'],
Expand Down Expand Up @@ -217,7 +221,7 @@ def after_request_log_status(response):
def set_security_headers(response):
security_headers = {
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
'X-Frame-Options': 'DENY',
'X-Frame-Options': None if re.match ('.*/quiz', request.url) else 'DENY',
'X-XSS-Protection': '1; mode=block',
}
response.headers.update(security_headers)
Expand Down Expand Up @@ -495,7 +499,7 @@ def get_quiz(level_source, question_nr, attempt):
is_teacher=is_teacher(request),
auth=TRANSLATIONS.get_translations (requested_lang(), 'Auth'))

@app.route('/submit_answer/<level_source>/<question_nr>/<attempt>', methods=["POST"])
@app.route('/quiz/submit_answer/<level_source>/<question_nr>/<attempt>', methods=["POST"])
def submit_answer(level_source, question_nr, attempt):
if not config.get('quiz-enabled') and g.lang != 'nl':
return 'Hedy quiz disabled!', 404
Expand Down
112 changes: 59 additions & 53 deletions coursedata/adventures/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ adventures:
```
## Searching turtle
You can also use `random` with the drawing turtle. A random choice makes the turtle walk a different path each time.
You can also use `random` with the drawing turtle. A random choice makes the turtle walk a different path each time.
Use `at random` to choose a value from a list. You can copy and paste lines 2 and 3 so create a longer random path.
## Example Hedy code
Expand All @@ -248,7 +248,7 @@ adventures:
story_text: |
## Let's draw
In level 3 you have to use quotation marks with `print` and `ask`. Also when drawing!
## Example Hedy code
```
print 'Drawing figures'
Expand Down Expand Up @@ -903,8 +903,8 @@ adventures:
8:
story_text: |
## Restaurant
We can use the `for i in range 1 to 5` to print the orders from multiple customers in an orderly manner.
We can use the `for i in range 1 to 5` to print the orders from multiple customers in an orderly manner.
## Example Hedy code
```
print 'Welcome to Restaurant Hedy!'
Expand All @@ -922,7 +922,7 @@ adventures:
print 'That will be ' price ' dollars, please!'
```
start_code: ""

fortune:
name: "Fortune teller"
description: "Let Hedy predict the future"
Expand Down Expand Up @@ -1203,7 +1203,7 @@ adventures:
story_text: |
## Haunted House
In level 7 you can repeat multiple lines of code, which allows you to make the haunted house even more interactive!
## Example Hedy code
```
print 'Escape from the Haunted House!'
Expand All @@ -1228,14 +1228,14 @@ adventures:
## Challenge
Now it's very hard to win this game, can you make it easier to win?
For example by only having 1 wrong door and 2 correct doors instead of 1 correct door en 2 wrong ones?
start_code: "print 'Escape from the haunted house!'"

8:
story_text: |
## Haunted House
In level 8 we've changed the repeat command and we've added a line to our haunted house that tells the player in which room they are.
In level 8 we've changed the repeat command and we've added a line to our haunted house that tells the player in which room they are.
## Example Hedy Code
```
print 'Escape from the Haunted House!'
Expand All @@ -1259,7 +1259,7 @@ adventures:
print 'Great! You survived!'
```
start_code: "print 'Escape from the haunted house!'"

next:
name: "What's next?"
description: "What's Next?"
Expand All @@ -1269,55 +1269,55 @@ adventures:
1:
story_text: |
## What's next?
Congratulations! You've reached the end of level 1. Hopefully you've already made some awesome codes, but Hedy has a lot more to discover.
In the first level you might've notice that the `echo` command can only save one bit of information at a time.
For example in the restaurant adventure, you could echo what the costumer wanted to eat, or what they wanted to drink, but not both in one sentence.
Congratulations! You've reached the end of level 1. Hopefully you've already made some awesome codes, but Hedy has a lot more to discover.
In the first level you might've notice that the `echo` command can only save one bit of information at a time.
For example in the restaurant adventure, you could echo what the costumer wanted to eat, or what they wanted to drink, but not both in one sentence.
```
print Welcome at Hedy's
ask What would you like to eat?
echo So you want...
ask what would you like to drink?
echo So you want...
```
If the player types a hamburger and coke, you can't say `so you woudl like a hamburger and coke`, but you have to make two seperate line.
If the player types a hamburger and coke, you can't say `so you woudl like a hamburger and coke`, but you have to make two seperate line.
Also, the `echo` command only echoes the word at the end of the sentence. So you can't say `your hamburger is coming right up!`.
That changes in level 2. In level 2 you'll learn to work with variables, that allow you to save multiple pieces of information and print them in any place you want.
Besides, you'll learn how to work with the `at random` command, that you can use to make games.
Besides, you'll learn how to work with the `at random` command, that you can use to make games.
So let's go to the next level!
start_code: "print Let's go!"
2:
story_text: |
## What's next?
In level 2 you've been practising with variables, but maybe you've come across this mistake.
Try to run this code:
```
name is Sophie
print My name is name
```
Of course you wanted to print `My name is Sophie` but Hedy prints `My Sophie is Sophie`.
In level 3 this problem is fixed by using quotation marks.
Of course you wanted to print `My name is Sophie` but Hedy prints `My Sophie is Sophie`.
In level 3 this problem is fixed by using quotation marks.
start_code: "print Let's go to the next level!"
3:
story_text: |
## What's next?
In level 2 and 3 you've already learned to use `at random` which made your games different every time you ran the code.
But it's not really interactive, the player doesn't have any influence on what happens in the game.
In level 4 you'll learn the `if` command, that allows you to give diffent responses in your program. This way you can programm a secret password for your computer for example.
So let's take a peak at level 4.
In level 2 and 3 you've already learned to use `at random` which made your games different every time you ran the code.
But it's not really interactive, the player doesn't have any influence on what happens in the game.
In level 4 you'll learn the `if` command, that allows you to give diffent responses in your program. This way you can programm a secret password for your computer for example.
So let's take a peak at level 4.
start_code: "print 'Lets go to the next level!'"
4:
story_text: |
## What's next?
Great job! You've reached the end of level 4, which means you have practiced with `if` and `else`. You have probably noticed that your codes are getting longer and longer.
## What's next?
Great job! You've reached the end of level 4, which means you have practiced with `if` and `else`. You have probably noticed that your codes are getting longer and longer.
For example if you want to program 'Happy Birthday'
```
print 'happy birthday to you'
print 'happy birthday to you'
Expand All @@ -1326,41 +1326,41 @@ adventures:
```
That's a lot of code for mainly the same words over and over again. Luckily level 5 has a solution with the `repeat` command, that allows you to repeat a line of code multiple times.
start_code: "print 'On to the next level!'"
5:
story_text: |
## What's next?
Now you've reached the end of level 5, so you've learned how to repeat a line of code. For example you can code your restaurant so that you can ask multiple guest what they would like to eat.
Now you've reached the end of level 5, so you've learned how to repeat a line of code. For example you can code your restaurant so that you can ask multiple guest what they would like to eat.
What you can't yet do though, is calculate the price for everyone's dinner.
Level 6 makes it possible to use addition, subtraction and multiplication in your programs. This way you can calculate the prices in your restaurant, but you could also add a secret code to give your friends and family a discount.
Level 6 makes it possible to use addition, subtraction and multiplication in your programs. This way you can calculate the prices in your restaurant, but you could also add a secret code to give your friends and family a discount.
Another option in level 6 is programming your own maths game, for your little brother or sister to practice their multiplications.
Go see for yourself in the next level!
start_code: "print 'On to the next level!'"
6:
story_text: |
## What's next?
In level 5 you've learned how to repeat one single line of code. This comes in handy, but it's not always enhough. Sometimes you want to repeat multiple lines at onece.
Level 7 allows you to group a couple of lines of code, and repeat that little group of lines all at once!
## What's next?
In level 5 you've learned how to repeat one single line of code. This comes in handy, but it's not always enhough. Sometimes you want to repeat multiple lines at onece.
Level 7 allows you to group a couple of lines of code, and repeat that little group of lines all at once!
```
repeat 5 times print 'In level 7 you can repeat multiple lines of code at once!'
```
start_code: "print 'Lets go to the next level!'"
7:
story_text: |
## What's next?
You have reached the end of level 7, you're doing great! You are about to go to level 8. In the higher levels, Hedy is focussing more and more on teaching you the programming language Python.
## What's next?
You have reached the end of level 7, you're doing great! You are about to go to level 8. In the higher levels, Hedy is focussing more and more on teaching you the programming language Python.
In Python there is no `repeat` command, but there is a command that works like repeat. Are you curious to find out how to say `repeat` in "real" programming language? Quickly go to level 8 to find out!
start_code: "print 'Lets go to the next level!'"
8:
story_text: |
## What's next?
Your code is looking more and more like a python code, great! In level 9 you will learn another small step to make it even more like python.
Another great thing you'll learn in level 9 is a new command. In level 8, you might have noticed that you sometimes could use another `else` in your code.
For example:
Your code is looking more and more like a python code, great! In level 9 you will learn another small step to make it even more like python.
Another great thing you'll learn in level 9 is a new command. In level 8, you might have noticed that you sometimes could use another `else` in your code.
For example:
```
print 'What is for dinner tonight?'
options is pizza, broccoli, green beans
Expand All @@ -1371,11 +1371,17 @@ adventures:
print 'Yikes...'
```
In this code it would be great to have 2x an `else` so you could have one option for the broccoli and one for the green beans. Level 9 comes with the new command `elif` that makes this possible!
So check out the next level now!
So check out the next level now!
start_code: "print 'Lets go to the next level!'"






end:
name: "End"
description: "Test your Hedy knowledge"
image: ""
default_save_name: ""
levels:
1:
story_text: |
## Closing remarks level 1
Now that you have seen level 1, you know how to make small stories and programs. Try the quiz to test your Hedy knowledge!
## start_code is only added because it is required by the schema of Adventures
start_code: ""
Loading

0 comments on commit 3ee401f

Please sign in to comment.