This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# verbose | |
if 2 + 2 == 4 | |
puts "Correct!" | |
end | |
# short-hand | |
puts "Correct" if 2 + 2 == 4 | |
# more realistic short-hand | |
def addition_problem(user_answer, correct_answer) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
questions = { | |
'one' => {text: "What is 2 + 2?", answer: 4}, | |
'two' => {text: "What is 4 + 7?", answer: 11}, | |
'three' => {text: "What is 7 + 3?", answer: 10}, | |
} | |
user_answers = { | |
'one' => 4, | |
'two' => 9, | |
'three' => 10 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
groceries = ["apple", "pear", "banana"] | |
groceries.each do |grocery| | |
puts grocery | |
end | |
# => | |
# apple | |
# pear | |
# banana |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ages = [16, 15.6, 16.25, 17.1, 16.4, 15.8] | |
total_years = 0.0 | |
ages.each do |age| | |
total_years += age | |
end | |
total_years / ages.size # => 16.191666666666666 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arr = [3, "four", {five: 'six'}] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
questions = {} # => create an empty Hash/object | |
questions['one'] = "What's your name?" | |
questions['two'] = "How old are you?" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
questions = { | |
'one' => "What's your name?", | |
'two' => "How old are you?" | |
} | |
questions['one'] # => returns "What's your name?" | |
questions['two'] # => returns "How old are you?" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
questions = { | |
'one' => "What's your name?", | |
'two' => "How old are you?" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$x = 4; | |
if ($x == 4) { | |
echo "Correct!"; | |
} else { | |
echo "Inorrect!"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int x = 4; | |
if (x == 4) { | |
System.out.println("Correct!"); | |
} else { | |
System.out.println("Inorrect!"); | |
} |