Skip to content

Instantly share code, notes, and snippets.

@ryanckulp
ryanckulp / if_x_y.rb
Created January 1, 2018 21:47
if example with 2 variables in Ruby
if x == y
alert "Correct!"
else
alert "Incorrect!"
end
@ryanckulp
ryanckulp / x_assignment_y_equals.rb
Created January 1, 2018 21:51
assignment and is-equal example in Ruby
x = 3
y = 3
x == y # => returns 'true'
x = 4
y = 5
x == y # => returns 'false'
@ryanckulp
ryanckulp / addition_method.rb
Created January 1, 2018 21:55
method with addition operation in Ruby
def addition_problem(user_answer, correct_answer)
if user_answer == correct_answer
alert "Correct!"
else
alert "Incorrect!"
end
end
# question 1, answer: 4
addition_problem(3, 4) # returns 'false'
@ryanckulp
ryanckulp / parameterless_methods.rb
Last active January 1, 2018 22:04
useful methods without parameters, in Ruby
def date_night?
Date.today.wday == 5 # is today the weekday 5 out of 7?
end
def bitcoin_price
Bitcoin.get_current_price
end
@ryanckulp
ryanckulp / if_else_python.py
Created January 1, 2018 22:29
if/else example in Python
if x == 5:
print("Correct!")
else:
print("Incorrect!")
@ryanckulp
ryanckulp / ifElse.js
Created January 1, 2018 22:31
if/else example in JavaScript
var x = 4;
if (x == 4) {
console.log("Correct!");
} else {
console.log("Incorrect!");
}
@ryanckulp
ryanckulp / if_else_java.java
Created January 1, 2018 22:40
if/else example in Java
int x = 4;
if (x == 4) {
System.out.println("Correct!");
} else {
System.out.println("Inorrect!");
}
@ryanckulp
ryanckulp / if_else_php.php
Created January 1, 2018 22:44
if/else example in PHP
<?php
$x = 4;
if ($x == 4) {
echo "Correct!";
} else {
echo "Inorrect!";
}
@ryanckulp
ryanckulp / hash.rb
Created January 1, 2018 22:51
hash example in Ruby
questions = {
'one' => "What's your name?",
'two' => "How old are you?"
}
@ryanckulp
ryanckulp / hash_bracket.rb
Created January 1, 2018 22:53
accessing a Hash key/value in Ruby
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?"