Presentation is loading. Please wait.

Presentation is loading. Please wait.

Functions and Custom Blocks to pluralize words

Similar presentations


Presentation on theme: "Functions and Custom Blocks to pluralize words"— Presentation transcript:

1 Functions and Custom Blocks to pluralize words

2 Basics – dog -> dogs We want to create a function that takes a STRING of text that changes the end of our STRING to be the plural version. Dog should change to Dogs. Pluralize (string) { Report ( Join ( string, ‘s’ ) ) }

3 Dog or Boss? We need to create a condition to check for.
Does the string end with an ‘s’? How do we find the last letter of a string?

4 Is Last Letter of (string) = ?
Above is the condition we want to create. In this case we want to check if the last letter is = ‘s’. IF ( Last Letter of ( string ) = s ) { Report ( Join ( string , ‘es’ ) ) }

5 Special Case - H How many special H cases or examples does plural-h activity ask us to program for? But how many outcomes or results do we need? If ( 2nd to last letter = c OR s ) then Join (String, ‘es’) If ( 2nd to last letter = t ) then Join (String, ‘s’) And the default Report (Join (string, ‘s’) Crutch – or ch Moth – th Bush - sh -> crutchES -> mothS -> bushES = Join ( string, ‘es’ ) = Join ( string, ‘s’ )

6 Special Case - Y Cases for words ending in Y:
a. If the word ends in a vowel (a,e,i,o,u) + y then just add s. boy/boys, journey/journeys, key/keys, tray/trays. b. If the word ends in a consonant + y then y changes to -ies country/countries, baby/babies, body/bodies, memory/memories, sky/skies, variety / varieties... The first case is easy, just add a ‘Y’. The 2nd case requires you to remove ALL BUT LAST LETTER OF the string. I wonder if there is a block that does that?

7 How do you replace more than one letter?
In special case Y, you used the ALL BUT LAST LETTER OF () block to drop the ‘y’ and add ‘ies’ instead. But there is no block to replace 2 or 3 or 4 letter from a string of characters. We’ll have to make one. First, let’s look at how the ALL BUT LAST LETTER OF block works. Find and open that block in the editor.


Download ppt "Functions and Custom Blocks to pluralize words"

Similar presentations


Ads by Google