Conditionals
Goals
Step 1
Type this in the file conditionals_test.rb:print "How many apples do you have? > " apple_count = gets.to_i puts "You have #{apple_count} apples."
Step 2
Type this in the file conditionals_test.rb:print "How many apples do you have? > " apple_count = gets.to_i if apple_count > 5 puts "Lots of apples!" else puts 'Not many apples...' endType this in the terminal:ruby conditionals_test.rb
Step 3
Step 4
Type this in the file while_loop.rb:total = 0 user_input = nil while user_input != 'stop' print 'Enter a number to add to the total. > ' user_input = gets.chomp total = total + user_input.to_i end puts "Your final total was #{total}!"Type this in the terminal:ruby while_loop.rb
Reto(s)
What is the first number? > 2 What is the second number? > 4 Would you like to add (1), subtract (2), multiply (3), or divide (4) these numbers? > 3 The product is 8What number do you want to include? > 2 What number do you want to include? > 4 What number do you want to include? > 6 What number do you want to include? > DONE Would you like to add (1), subtract (2), multiply (3), or divide (4) these numbers? > 3 The product is 48
Explicación
Next Step:
Go on to nil