summaryrefslogtreecommitdiff
path: root/exercises/01_variables
diff options
context:
space:
mode:
Diffstat (limited to 'exercises/01_variables')
-rw-r--r--exercises/01_variables/README.md9
-rw-r--r--exercises/01_variables/variables1.rs13
-rw-r--r--exercises/01_variables/variables2.rs15
-rw-r--r--exercises/01_variables/variables3.rs11
-rw-r--r--exercises/01_variables/variables4.rs13
-rw-r--r--exercises/01_variables/variables5.rs13
-rw-r--r--exercises/01_variables/variables6.rs11
7 files changed, 85 insertions, 0 deletions
diff --git a/exercises/01_variables/README.md b/exercises/01_variables/README.md
new file mode 100644
index 0000000..7964ff2
--- /dev/null
+++ b/exercises/01_variables/README.md
@@ -0,0 +1,9 @@
+# Variables
+
+In Rust, variables are immutable by default.
+When a variable is immutable, once a value is bound to a name, you can’t change that value.
+You can make them mutable by adding `mut` in front of the variable name.
+
+## Further information
+
+- [Variables and Mutability](https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html)
diff --git a/exercises/01_variables/variables1.rs b/exercises/01_variables/variables1.rs
new file mode 100644
index 0000000..b3e089a
--- /dev/null
+++ b/exercises/01_variables/variables1.rs
@@ -0,0 +1,13 @@
+// variables1.rs
+//
+// Make me compile!
+//
+// Execute `rustlings hint variables1` or use the `hint` watch subcommand for a
+// hint.
+
+// I AM NOT DONE
+
+fn main() {
+ x = 5;
+ println!("x has the value {}", x);
+}
diff --git a/exercises/01_variables/variables2.rs b/exercises/01_variables/variables2.rs
new file mode 100644
index 0000000..e1c23ed
--- /dev/null
+++ b/exercises/01_variables/variables2.rs
@@ -0,0 +1,15 @@
+// variables2.rs
+//
+// Execute `rustlings hint variables2` or use the `hint` watch subcommand for a
+// hint.
+
+// I AM NOT DONE
+
+fn main() {
+ let x;
+ if x == 10 {
+ println!("x is ten!");
+ } else {
+ println!("x is not ten!");
+ }
+}
diff --git a/exercises/01_variables/variables3.rs b/exercises/01_variables/variables3.rs
new file mode 100644
index 0000000..86bed41
--- /dev/null
+++ b/exercises/01_variables/variables3.rs
@@ -0,0 +1,11 @@
+// variables3.rs
+//
+// Execute `rustlings hint variables3` or use the `hint` watch subcommand for a
+// hint.
+
+// I AM NOT DONE
+
+fn main() {
+ let x: i32;
+ println!("Number {}", x);
+}
diff --git a/exercises/01_variables/variables4.rs b/exercises/01_variables/variables4.rs
new file mode 100644
index 0000000..5394f39
--- /dev/null
+++ b/exercises/01_variables/variables4.rs
@@ -0,0 +1,13 @@
+// variables4.rs
+//
+// Execute `rustlings hint variables4` or use the `hint` watch subcommand for a
+// hint.
+
+// I AM NOT DONE
+
+fn main() {
+ let x = 3;
+ println!("Number {}", x);
+ x = 5; // don't change this line
+ println!("Number {}", x);
+}
diff --git a/exercises/01_variables/variables5.rs b/exercises/01_variables/variables5.rs
new file mode 100644
index 0000000..a29b38b
--- /dev/null
+++ b/exercises/01_variables/variables5.rs
@@ -0,0 +1,13 @@
+// variables5.rs
+//
+// Execute `rustlings hint variables5` or use the `hint` watch subcommand for a
+// hint.
+
+// I AM NOT DONE
+
+fn main() {
+ let number = "T-H-R-E-E"; // don't change this line
+ println!("Spell a Number : {}", number);
+ number = 3; // don't rename this variable
+ println!("Number plus two is : {}", number + 2);
+}
diff --git a/exercises/01_variables/variables6.rs b/exercises/01_variables/variables6.rs
new file mode 100644
index 0000000..853183b
--- /dev/null
+++ b/exercises/01_variables/variables6.rs
@@ -0,0 +1,11 @@
+// variables6.rs
+//
+// Execute `rustlings hint variables6` or use the `hint` watch subcommand for a
+// hint.
+
+// I AM NOT DONE
+
+const NUMBER = 3;
+fn main() {
+ println!("Number {}", NUMBER);
+}