summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorolivia <olivia@fastmail.com>2018-05-22 21:22:21 +0200
committerolivia <olivia@fastmail.com>2018-05-22 21:22:21 +0200
commit6d5096534454ae934328f9ed634f58fae7f208f9 (patch)
tree4671d9d4a0f0ce698ac1bf7748a1c8d34e4137ef /src
parent729217da2f6307f409c5f41b79d64b92c7276e97 (diff)
port the first exercise from the old curriculum
Diffstat (limited to 'src')
-rw-r--r--src/about_variables.rs55
1 files changed, 32 insertions, 23 deletions
diff --git a/src/about_variables.rs b/src/about_variables.rs
index ab2f143..bef8049 100644
--- a/src/about_variables.rs
+++ b/src/about_variables.rs
@@ -1,29 +1,38 @@
-fn guess_this() -> i32 {
- let one = 5;
- let two = 7;
- let three = 3;
- let result = (one + two) / three;
- return result;
-}
+// Welcome to Rustlings! If you're here, that means you've either successfully
+// downloaded Rustlings, or are looking at this on GitHub. Either way, let me
+// introduce you to one of the most basic elements of Rust:
+//
+// === VARIABLES ===
+//
+// Variables are essentially little containers that hold, well, something. Think
+// of them as a little cardboard box that you put stuff into. What can you put
+// into a virtual cardboard box in Rust? All kinds of stuff, it turns out!
+// Numbers, words, sequences, and much more. Let's start out simple, though.
+// Here's our first exercise:
-fn simple() -> &'static str {
- let hello = "Hello World!";
- return hello;
+pub fn exercise_one() {
+ let x = 5;
+ verify!(0, x, "Number assignment");
+ // ^ ^
+ // | |
+ // What's The variable
+ // in it itself
}
-mod tests {
- use super::*;
-
- pub fn test_simple() {
- verify!("Hello World!", simple(), "Simple example");
- }
-
- pub fn test_complicated() {
- verify!(1, guess_this(), "Complicated example");
- }
-}
+// Did you get all that? The "let" word basically tells us that we now want to
+// define a variable, and what follows it, the "x" is the name of the variable.
+// Each variable has a name, like a label you put on your cardboard box so you
+// don't confuse it with another, similar looking one.
+// The whole "verify!" deal essentially means that Rustlings is checking if you
+// solved the exercise correctly. It compares the first argument with the
+// second, so in this case "0" with "x", where "x" is the _value_ of the variable
+// we called "x". When you write "x", you pull out the cardboard box labelled "x"
+// and take out what's inside of it.
+// Speaking of which, what *is* inside of our "x" cardboard box? I don't think it's
+// "0"... do you know? Replace the "0" with the value of the variable we defined.
+// After that, run "cargo run" in your command line, and see if you put in the
+// right answer.
pub fn exec() {
- tests::test_simple();
- tests::test_complicated();
+ exercise_one();
}