Skip to content

Commit 8c64c39

Browse files
authored
adding tutorial "Printing variables and strings" (ronreiter#712)
* add tutorial "Printing variables and strings" * Add "Printing variables and strings"
1 parent 2a7eff8 commit 8c64c39

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Tutorial
2+
--------
3+
4+
Printing variables and strings
5+
6+
You've learned how to use and print variables and strings. But what if you wanted to print a phrase using variables and strings together?
7+
8+
In Ruby you can call a variable inside the string what you want to print.
9+
10+
To call the variable you neet to use `#{variable}`. For example:
11+
12+
number = 8
13+
puts "I have #{number} oranges." # I have 8 oranges
14+
15+
You can even make math operations between variables inside it.
16+
17+
first_number = 5
18+
second_number = 6
19+
20+
puts "Multiplying #{first_number} by #{second_number} the result is #{first_number * second_number}"
21+
22+
23+
Exercise
24+
--------
25+
Modifiy the code to print using the variables:
26+
- How many apples each of the kids have;
27+
- The sum of all the apples.
28+
29+
Tutorial Code
30+
-------------
31+
john = 5
32+
mary = 3
33+
will = 2
34+
35+
puts "John has apples."
36+
puts "Mary has apples."
37+
puts "Will has apples."
38+
puts "Together they have apples."
39+
40+
Expected Output
41+
---------------
42+
John has 5 apples.
43+
Mary has 3 apples.
44+
Will has 2 apples.
45+
Together they have 10 apples.
46+
47+
48+
Solution
49+
--------
50+
john = 5
51+
mary = 3
52+
will = 2
53+
54+
puts "John has apples."
55+
puts "Mary has apples."
56+
puts "Will has apples."
57+
puts "Together they have apples".

tutorials/learnrubyonline.org/en/Welcome.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ learnrubyonline.org is still under construction - If you wish to contribute tuto
1515
- [[Variables and Types]]
1616
- [[Math]]
1717
- [[Strings]]
18+
- [[Printing variables and strings]]
1819
- [[Arrays]]
1920
- [[Hashes and Symbols]]
2021
- [[Conditional Statements]]

0 commit comments

Comments
 (0)