Skip to content

Instantly share code, notes, and snippets.

@fmaylinch
Last active March 29, 2016 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fmaylinch/8e49ccad29998c08c733 to your computer and use it in GitHub Desktop.
Save fmaylinch/8e49ccad29998c08c733 to your computer and use it in GitHub Desktop.
title: Sample Lesson
author: Ferran Maylinch
# Minimum app version needed for this lesson
minAppVersion: "1.0"
exercises:
- title: Sample Exercise
# `intro` is displayed when the exercise is started.
# It's a list of `text` (with some basic Markdown), `image` and `code` sections.
intro:
- text: "**Jess** is an app that helps you learn programming by using [JavaScript](https://www.javascript.com)."
- image: http://i.imgur.com/WEA5N6k.png
- text: As a sample exercise, you will print your name using the **`log`** function.
- code: |
// Example
log("Jess");
- text: >
Your task is simple: in the editor below, just **write your name between the quotes**,
and then run the code using the `RUN` button.
# `code` is optional (it's the initial code in the editor)
code: |
// Write your name inside the quotes
log("");
# `check` is optional but you will usually want to check whether the user completed the task.
# It's a js function that receives an object containing `logs` (array) and `tries` (number).
# If the user doesn't pass the task return: { ok:false, message:"some message or hint" }
# If the user passes the task return: { ok:true, ... }. Any properties you add can be used in explanation.
check: |
function(jess) {
if (jess.logs.length >= 1 && jess.logs[0]) {
return { ok:true, name:jess.logs[0] };
} else if (jess.logs.length > 1) {
return { ok:false, message:"Use the `log` function just once" };
} else if (jess.logs.length === 0 || jess.logs[0].length == 0) {
return { ok:false, message:"Write something inside the quotes." };
}
}
# `explanation` is displayed after the task is successfully completed (structured like `intro`)
# You can use properties added to the result object you return in `check`.
explanation:
- text: Well done **{{name}}**! After you complete an exercise, you will see some explanation about what you learnt.
- text: In this case, you have printed your name in the console (the brown view) using the `log` function.
- text: That was awesome, right? And many more exciting exercises are awaiting!
- title: Current year?
intro:
- text: Print the current year
code: log("");
check: |
function(jess) {
if (jess.logs.length >= 1 && jess.logs[0] == new Date().getFullYear()) {
return { ok:true };
} else {
return { ok:false, message:"Nope! You tried " + jess.tries + " times." };
}
}
explanation:
- text: You're a clever person!
- title: Declare a variable
intro:
- text: Declare a variable named `age` and assign your age to it.
check: |
function(jess) {
if ( typeof(age) === 'undefined' ) {
return { ok:false, message:"You didn't declare the variable `age` or assigned anything to it." };
} else if ( typeof(age) !== 'number' ) {
return { ok:false, message:"You didn't asign a number to the variable `age`." };
} else if ( age < 1 || age > 130 ) {
return { ok:false, message:"Assign a reasonable number..." };
} else {
return { ok:true, age:age.toString() }; // It's better to always pass strings
}
}
explanation:
- text: You're {{age}} years old?? Really??
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment