Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HW-Done #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
i = 1
while i <= 100
# Your code goes in here.
if i % 3 == 0 and i % 5 == 0
puts "FizzBuzz"
elsif i % 3 == 0
puts "Fizz"
elsif i % 5 == 0
puts "Buzz"
else puts i
end
i+=1
end
28 changes: 14 additions & 14 deletions data-collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,89 +9,89 @@ planeteers = ["Earth", "Wind", "Captain Planet", "Fire", "Water"]
Access the second value in `planeteers`.

```rb
# Your answer here
planeteers[1]
```

Add "Heart" to the end of `planeteers`.

```rb
# Your answer here
planeteers << "Heart"
```

Remove "Captain Planet" from the array (without using a method).

```rb
# Your answer here
planeteers -= ["Captain Planet"]
```

Combine `planeteers` with `rangers = ["Red", "Blue", "Pink", "Yellow", "Black"]` and save the result in a variable called `heroes`.

```rb
# Your answer here
heroes = planeteers + rangers
```

Alphabetize the contents of `heroes` using a method. [The Ruby documentation might help](http://ruby-doc.org/core-2.2.0/Array.html).

```rb
# Your answer here
heroes.sort
```

Randomize the contents of `heroes` using a method. [The Ruby documentation might help](http://ruby-doc.org/core-2.2.0/Array.html).

```rb
# Your answer here
heroes.shuffle
```

#### Bonus

Select a random element from `heroes` using a method. [The Ruby documentation might help](http://ruby-doc.org/core-2.2.0/Array.html).

```rb
# Your answer here
heroes.sample
```

Select all elements in `heroes` that begin with "B" using a method. [The Ruby documentation might help](http://ruby-doc.org/core-2.2.0/Array.html).

```rb
# Your answer here
heroes.select {|el| el.start_with?('B')}
```

### Hashes

Initialize a hash called `ninja_turtle` with the properties `name`, `weapon` and `radical`. They should have values of "Michelangelo", "Nunchuks" and `true` respectively.

```rb
# Your answer here
ninja_turtle = {:name => "Michelangelo", :weapon => "Nunchuks", :radical => true}
```

Add a key `age` to `ninja_turtle`. Set it to whatever numerical value you'd like.

```rb
# Your answer here
ninja_turtle = ninja_turtle.merge(:age=>3)
```

Remove the `radical` key-value pair from `ninja_turtle`.

```rb
# Your answer here
ninja_turtle.delete(:radical)
```

Add a key `pizza_toppings` to `ninja_turtle`. Set it to an array of strings (e.g., `["cheese", "pepperoni", "peppers"]`).

```rb
# Your answer here
ninja_turtle = ninja_turtle.merge(:pizza_toppings => ["cheese", "pepperoni","peppers"])
```

Access the first element of `pizza_toppings`.

```rb
# Your answer here
ninja_turtle[:pizza_toppings][0]
```

Produce an array containing all of `ninja_turtle`'s keys using a method. [The Ruby documentation might help](http://ruby-doc.org/core-1.9.3/Hash.html).

```rb
# Your answer here
ninja_turtle.keys
```

#### Bonus
Expand Down
24 changes: 12 additions & 12 deletions data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,59 +10,59 @@
2 ** 3
```
```text
Your answer.
8
```

```rb
((16 / 4) * (2 + 1)) ** 2
```
```text
Your answer.
144
```

```rb
("a milli " + "a milli") * 3
```
```text
Your answer.
"a milli a millia milli a millia milli a milli"
```

```rb
("a milli " * 4) / 2
```
```text
Your answer.
Error out
```

```rb
my_favorite_number = 13
puts "My favorite number is: " + my_favorite_number
```
```text
Your answer.
Error out
```

```rb
my_favorite_number = 13
puts "My favorite number is: #{my_favorite_number}"
```
```text
Your answer.
My favorite number is: 13
```

### Truthiness and Falsiness

#### Which of these evaluate as `false` in Ruby? Mark all that apply.

```text
[ ] false
[ false ] false
[ ] 0
[ ] ""
[ ] null
[ ] [ ] (empty array)
[ ] undefined
[ ] NaN
[ ] nil
[ false ] nil
```

#### What are the outputs and/or side effects of the following code snippets?
Expand All @@ -78,7 +78,7 @@ if no_name
end
```
```text
Your answer.
My name is:
```

```rb
Expand All @@ -88,7 +88,7 @@ if no_name
end
```
```text
Your answer.
nil
```

```rb
Expand All @@ -98,7 +98,7 @@ if age
end
```
```text
Your answer.
Error out
```

```rb
Expand All @@ -108,7 +108,7 @@ if age
end
```
```text
Your answer.
My age is: 20
```

### Conditionals
Expand Down