Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

What's wrong with my Ruby code?

I have been playing around on CodeCademy with some Ruby since yesterday, and I feel as though I am grasping it slightly, but a few issues are becoming visible.

What is wrong with this code? I keep getting an error:

Code
(ruby):15: syntax error, unexpected $end, expecting keyword_end

Code:
Code
print "What grade did you get on your final?"
grade = gets.chomp
if grade > 1
    puts "You're just making that up! Really?"
answer = gets.chomp
yes = true
no = false

if answer == true
    print "Oh, that's awesome!"
if answer == false
    print "Dang, I thought you were serious."
else
    print "What? I don't understand."
end

Thanks. It's always the simplest of issues that stump me..

EDIT:
I fixed it by doing this:
Code
print "What grade did you get on your final?"
grade = Integer(gets.chomp)
if grade > 1
    puts "You're just making that up! Really?"
answer = gets.chomp
if answer == "yes"
    puts "Oh, that's awesome!"
end
if answer == "no"
    puts "Dang, I thought you were serious."
end
else
    print "What? I don't understand."
end
But now, I can't figure out how to get the else statement to work correctly.
http://pastebin.com/1hpXqKEX
(Jul 21, 2015 08:30 AM)scam. Wrote:  http://pastebin.com/1hpXqKEX

Thanks man! I ended up fixing it 20 mins later, but didn't realize you could substitute "puts" with p.

You know you don't have to use several #'s for a multi-line comment?
Just use:
Code
=begin
This is
a multi-line
comment
=end

But still, thanks man! These tips are really helpful!
(Jul 21, 2015 01:48 PM)Auxil Wrote:  Thanks man! I ended up fixing it 20 mins later, but didn't realize you could substitute "puts" with p.

You know you don't have to use several #'s for a multi-line comment?
Just use:
Code
=begin
This is
a multi-line
comment
=end

But still, thanks man! These tips are really helpful!

I just think the #s look better. 🙂 just as easy to add with vim too.
(Jul 21, 2015 08:19 PM)scam. Wrote:  I just think the #s look better. 🙂 just as easy to add with vim too.

Yeah. Thanks man.
What can I do with Ruby? I can't figure out how to implement a script into a webpage.

Is that even possible?

I really want to do something with Ruby, so I can stay interested in it. I lose interest extremely fast, which is horribly annoying for me. I really want to focus on one thing, but it's very hard.

Thanks.
(Jul 21, 2015 11:43 PM)Auxil Wrote:  Yeah. Thanks man.
What can I do with Ruby? I can't figure out how to implement a script into a webpage.

Is that even possible?

I really want to do something with Ruby, so I can stay interested in it. I lose interest extremely fast, which is horribly annoying for me. I really want to focus on one thing, but it's very hard.

Thanks.

For websites you should look at something like Ruby on Rails. I have only looked into it a little bit but it is an extrememly solid framework for making websites using ruby.

As for stuff to do, I mostly use it for automation and making small scripts to make my life easier. For example scraping web pages, processing lists, creating files/directories, etc. Just recently I made a script using the tinypng api to optimize images. Just stuff like that mostly.

If you're interested in making web applications definitely take the time to learn RoR. It will take a bit to get used to but it is very powerful. There is even a course on CodeAcadamy. https://www.codecademy.com/courses/learn-rails
(Jul 22, 2015 12:18 AM)scam. Wrote:  For websites you should look at something like Ruby on Rails. I have only looked into it a little bit but it is an extrememly solid framework for making websites using ruby.

As for stuff to do, I mostly use it for automation and making small scripts to make my life easier. For example scraping web pages, processing lists, creating files/directories, etc. Just recently I made a script using the tinypng api to optimize images. Just stuff like that mostly.

If you're interested in making web applications definitely take the time to learn RoR. It will take a bit to get used to but it is very powerful. There is even a course on CodeAcadamy. https://www.codecademy.com/courses/learn-rails

I was planning to finish the Ruby course before attempting Rails. Currently like 25% done with the course. About three days in, and a few hours each day working on it, plus some buffer time when I have issues with my code, or get distracted.
(Jul 22, 2015 01:25 AM)Auxil Wrote:  I was planning to finish the Ruby course before attempting Rails. Currently like 25% done with the course. About three days in, and a few hours each day working on it, plus some buffer time when I have issues with my code, or get distracted.

Personally I learned Sinatra+ActiveRecord before Rails, because I just couldn't get the idea of this whole MVC part, however soon as I started making a little big projects I understood it and switching to Rails wasn't that big problem, it actually makes big code easier to split and security much much easier to implement. However if you're going for small testing stuff Rails will be over kill. Try to expand the number of tools you can use and make sure you know which one is suitable for what stuff.
On a side note, you can try making games with Ruby, there's a gem Gosu that helps you, and you can try making Android apps if you google around (because I forgot the names <.<)
Have a cool signature? hit me up and I might use it.


Possibly Related Threads...
Thread / Author Replies Views Last Post
by twitter4uMay 2, 2020 04:37 AM 0 54 May 2, 2020 04:37 AM
Last Post: twitter4u
[Tutorial] by ruka urushibaharaAug 22, 2018 05:37 AM 0 167 Aug 22, 2018 05:37 AM
Last Post: ruka urushibahara
[Source] by Toph BeifongFeb 7, 2016 02:57 AM 2 151 Feb 7, 2016 02:57 AM
Last Post: Toph Beifong