Strings are ordered collections of characters, which are strings of length 1. The characters in a string can be accessed using bracket notation.
Arrays are ordered collections of items, which can be strings, numbers, other arrays, etc. The items/elements/entries stored in an array can be accessed using bracket notation.
Strings are immutable, whereas arrays can be changed.
Strings and arrays have properties and methods that allow us to easily perform some useful actions. Remember, some of the methods will create a copy of the original string, while others create an new string, which will need to be stored.
Use string methods to convert a word into pseudo-pig latin.
"LaunchCode"
becomes "nchCodeLau"
. Use string interpolation to
print the original and modified string in a descriptive phrase.The Split
and Join
methods convert back and forth between strings
and arrays. Use delimiters as reference points to split a string into an
array, then modify the array and convert it back to a printable string.
Contains
method to check to see if the
words are separated by commas (,
), semicolons (;
) spaces, or colons (:
).Split
it into an array,
reverse the entries, and then Join
the array into a new comma separated
string. For example, "up,to,code,fun"
becomes "fun,code,to,up"
.Split
it into an
array, alphabetize the entries, and then Join
the array into a new
hyphen separated string. For example, "up;to;code;fun"
becomes
"code-fun-to-up"
.Split
it into an array,
reverse alphabetize the entries, and then Join
the array into a new
space separated string. For example, "to code up fun"
becomes
"up to fun code"
.,
) are part of the final string. For example, "up:to:code:fun"
becomes "fun, code, to, up"
.Arrays can store other arrays!
cargoHold
to store arrays.{"water bottles", "meal packs", "snacks", "chocolate"}
{"space suits", "jet packs", "tool belts", "thermal detonators"}
{"parrots", "cats", "moose", "alien eggs"}
{"blankets", "pillows", "eyepatches", "alarm clocks"}
cargoHold's
structure.cargoHold
.cargoHold
AND a particular item. Use string interpolation to print a
message about the selected item. If the user entered an invalid number,
print an error message instead.