Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # CareerFoundry Exercise 21
- # this is a comment
- # puts is "put string".
- # this will output without any "" on the terminal because it is already a string value
- puts "hello, world!"
- puts "42"
- # p is for "print"
- p "hello, world again using p!"
- p 42 + 200
- p 84 * 4
- # METHODS
- def greeting(name) # define the method using the def keyword. this is like a function in js
- p "hello" + " " + name # code goes here
- end # always end/close the method using the "end" keyword
- greeting("Ekel") # call the method using its name
- # METHODS USING VARIABLES
- my_name = "Ekel Duran Echevarria" # define variable. small caps, snake_case preferred
- def greeting_by_variable(my_name)
- p "hello" + " " + my_name
- end
- greeting_by_variable(my_name)
- # METHOD WITH USER INPUT
- def greeting_with_user_input
- puts "Please enter your name"
- username = gets.chomp # gets = "get string". chomp will remove new line
- puts "Hello, " + username
- end
- greeting_with_user_input # call method. no arguments necessary.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement