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

Finished HW with some bonuses #15

Open
wants to merge 6 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
49 changes: 49 additions & 0 deletions app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
i = 1
while i <= 100
if i % 3 ===0
puts "Fizz"

elsif i % 5 === 0
puts "Buzz"

elsif i % 3 ===0 && i % 5 ===0
puts "FizzBuzz"

else
puts i

end
i += 1
end

# planeteers = ["Earth", "Wind", "Captain Planet", "Fire", "Water"]

# puts planeteers[1]

# planeteers << "Heart"

# puts planeteers

# rangers = ["Red", "Blue", "Pink", "Yellow", "Black"]

# heroes = planeteers + rangers

# puts heroes.sort.inspect

# puts heroes.rand

# ninja_turtle = {
# name: "Michelangelo",
# weapon: "Nunchuks",
# radical: true
# }

# ninja_turtle = {:age => 15}

# ninja_turtle.without(:radical)

# ninja_turtle.store(:pizza_toppings, ["cheese", "pepperoni", "peppers"])

# ninja_turtle.pizza_toppings[0]

# ninja_turtle.to_a
30 changes: 17 additions & 13 deletions data-collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,45 @@ planeteers = ["Earth", "Wind", "Captain Planet", "Fire", "Water"]
Access the second value in `planeteers`.

```rb
# Your answer here
planeteers[1] ==> accessing the second element
```

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 ==> same as concat but without mutate
```

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
puts 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
puts 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
puts heroes.shuffle
```

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).
Expand All @@ -61,37 +61,41 @@ Select all elements in `heroes` that begin with "B" using a method. [The Ruby do
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 = {:age => 15}
```

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
inja_turtle.store(: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.to_a
```

#### Bonus
Expand Down
36 changes: 18 additions & 18 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 ==> 2 * 2 * 2
```

```rb
((16 / 4) * (2 + 1)) ** 2
```
```text
Your answer.
144 ==> 16/4 = 4, 2+1 = 3, 4*3 = 12, 12 * 12 = 144
```

```rb
("a milli " + "a milli") * 3
```
```text
Your answer.
a milli a millia milli a millia milli a milli ==> it would pritn it 3 times.
```

```rb
("a milli " * 4) / 2
```
```text
Your answer.
Error ==> because a milli is string and /2 is int
```

```rb
my_favorite_number = 13
puts "My favorite number is: " + my_favorite_number
```
```text
Your answer.
Error ==> + variableName means int and it would print string.
```

```rb
my_favorite_number = 13
puts "My favorite number is: #{my_favorite_number}"
```
```text
Your answer.
My favorite number is: 13 ==> because we put #{variableName}
```

### Truthiness and Falsiness

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

```text
[ ] false
[ ] 0
[ ] ""
[ ] null
[ ] [ ] (empty array)
[ ] undefined
[ ] NaN
[ ] nil
[false] false
[true ] 0
[true ] ""
[false ] null
[false] [ ] (empty array)
[false] undefined
[false ] NaN
[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: ==>> prints it empty.
```

```rb
Expand All @@ -88,7 +88,7 @@ if no_name
end
```
```text
Your answer.
==> yes, nothing. Because the condition returns false
```

```rb
Expand All @@ -98,7 +98,7 @@ if age
end
```
```text
Your answer.
Error ==> because age is int and the rest is string. If you want to print it, you should put #{age}
```

```rb
Expand All @@ -108,7 +108,7 @@ if age
end
```
```text
Your answer.
My age is: "User Input" ==> gets = means wait for the user to put something, while chomp break the line.
```

### Conditionals
Expand Down