Arrays of Strings
String Arrays
Tasks A
Go to Activity: Arrays of Strings. Complete the following tasks with the sample code in Example #1.
Task 1a
- Use a for index loop to reduce the redundancy in princessMonologue, without changing the behavior of the code.
- Add (at least) three more strings to the text list array, describing what she had for lunch.
- Use length of array so that it will loop through the entire array no matter the size.
Shared project link:
Task 1a Challenge
After the princess has given her speech, make her say it again backwards.
Shared project link:
Task 1b
- Replace the for index from 0 to loop with a for element loop.
- Replace text list get value at index with the value parameter of the for element loop.
- Make the princess introduce herself and let us know what she had for lunch.
Shared project link:
Princess Dialog Mod
- MakeCode.com Princess Dialog 2 Game
- Mod this game to add an Enemy Sprite.
- Create a second Text Array that includes words the Enemy will say.
- When the Princess overlaps with the Enemy, have the Enemy randomly say one of the words from the Array.
Shared project link:
Tasks B
Extension activities - if you complete your activities early, here are some optional challenges.
Challenge 1
- Create a list of 10 names of friends.
- Create a function that searches the list for a specific name, returning the name if found, and a message of "name not found" if the name is not found.
Challenge 2
- Use your list of 10 names.
- Create a program that randomly selects the name "out of a hat".