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

Example code is incorrect in lesson 40 #85

Open
skylarmacdonald opened this issue Jul 22, 2020 · 1 comment
Open

Example code is incorrect in lesson 40 #85

skylarmacdonald opened this issue Jul 22, 2020 · 1 comment

Comments

@skylarmacdonald
Copy link

"40": {"lang": "EN", "title": "All together now", "chapter": "N", "answer": "%5E4$", "ok": "Yes,%20Shakespeare%20wrote%204%20plays%20in%201591", "error": "Answer%20for%20the%20year%201591%20should%20be%204", "text": "%3Cp%3ENow%20suppose%20we%20only%20want%20to%20know%20the%20names%20and%20number%20of%20plays%20written%20by%20Shakespeare%0Ain%20a%20certain%20year.%3C/p%3E%0A%0A%3Cp%3ERuby%20lets%20us%20%3Cstrong%3Eselect%3C/strong%3E%20values%20from%20a%20hash.%20The%20select%20method%20uses%20a%20block%20to%20let%20us%0Adefine%20what%20to%20select%20and%20returns%20what%20it%20found.%3C/p%3E%0A%0A%3Cp%3EWe%20can%20then%20use%20the%20results%20returned%20by%20%3Cstrong%3Eselect%3C/strong%3E%20in%20the%20%3Cstrong%3Eeach%3C/strong%3E%20method%20as%20before%20by%0Asimply%20adding%20it%20after%20the%20select%20block.%20This%20is%20another%20example%20of%20method%20chaining,%20which%20we%20saw%0Aearlier%20when%20reversing%20a%20poem.%3C/p%3E%0A%0A%3Cp%3EI%20have%20prepared%20the%20%3Cstrong%3Ecount_plays%3C/strong%3E%20method%20for%20you.%20See%20if%20you%20can%20find%20out%20how%20many%20plays%0Awere%20written%20by%20Shakespeare%20in%20the%20year%20%3Cstrong%3E1591%3C/strong%3E.%20Try%20this:%3C/p%3E%0A%0A%3Cpre%3E%3Ccode%3Edef%20count_plays(year)%0A%20%20s%20=%20get_shakey%0A%0A%20%20s["William%20Shakespeare"]%0A%20%20%20%20.select%20%7B%20%7Ck,%20v%7C%0A%20%20%20%20%20%20v["finished"]%20==%20year%0A%20%20%20%20%7D.each%20%7B%20%7Ckey,%20val%7C%0A%20%20%20%20%20%20puts%20val["title"]%0A%20%20%20%20%7D.count%0Aend%0A%0Aputs%20count_plays(0)%0A%3C/code%3E%3C/pre%3E%0A%0A%3Cp%3EDid%20you%20notice%20that%20I%20chained%20the%20count%20method%20at%20the%20end%20of%20the%20each%20method.%20This%20gives%0Aus%20a%20return%20value%20for%20the%20%3Cstrong%3Ecount_plays%3C/strong%3E%20method.%3C/p%3E%0A%0A%3Cp%3EThere%20is%20another%20possibility%20for%20chaining%20here.%20See%20that%20lonely%20line%20%3Cstrong%3Es%20=%20get_shakey%3C/strong%3E.%0AYou%20could%20add%20the%20%3Cstrong%3E[“William%20Shakespeare”].select%20%7B%20%7Ck,%20v%7C%3C/strong%3E%20at%20the%20end%20of%20get_shakey%0A(no%20dot%20needed%20in%20this%20case).%3C/p%3E%0A", "load_code": "prev"},

The text in this lesson is asking the user to find the number of plays Shakespeare wrote in 1591 using the count_plays method, but in the example code, count_plays is called with a year value of 0. As a result the code errors if not modified.

The last line of the example code should read as follows:

puts count_plays(1591)

If nobody else beats me to it, I'll gladly open a PR for this when I have a bit more time.

@easydatawarehousing
Copy link
Collaborator

Thanks for your remark. The example code shows a zero on purpose, so the user has to do a bit of typing him- or herself. Most of the lessons do indeed have example code that works straight away. Some lessons the user has to change a few lines of code. This is meant to keep tryruby (absolute) beginner friendly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants