The aim of this puzzle: Print out the number of characters in the sentence
.
Walkthrough of the solution: The starter code starts by printing out the whole sentence
. It’s a string that is something like, A group of porcupines is called a prickle.
.
The next line of code prints the number 4
. The 4
is coming from 'toad'.length
. When .length
is attached to a string, it counts the number of characters in that string. It can be used directly on a string, like 'toad'.length
. Or it can be used on a string that’s stored in a variable, like sentence.length
.
Since we want to know the total number of characters (letters, numbers, spaces, punctuation marks) in the sentence
, we can change the 2nd print()
into print(sentence.length)
.
Sample code solution:
(Tap below to reveal)
print(sentence);
print(sentence.length);
JavaScript Concepts: String Properties, .length
, If Statements, Comparison Operators, Identifiers
Grasshopper Concepts: print()
Additional Code (hidden code that runs before the puzzle’s code):
let groups = [
['apes', 'a shrewdness'],
['badgers', 'a cete'],
['bats', 'a colony'],
['bears', 'a sleuth'],
['bees', 'a swarm'],
['buffalo', 'a gang'],
['camels', 'a caravan'],
['cats', 'a clowder'],
['kittens', 'a litter'],
['wild cats', 'a destruction'],
['cobras', 'a quiver'],
['crocodiles', 'a bask'],
['crows', 'a murder'],
['dogs', 'a pack'],
['puppies', 'a litter'],
['donkeys', 'a drove'],
['eagles', 'a convocation'],
['elephants', 'a parade'],
['elk', 'a gang or a herd'],
['falcons', 'a cast'],
['ferrets', 'a business'],
['fish', 'a school'],
['flamingos', 'a stand'],
['fox', 'a charm'],
['frogs', 'an army'],
['geese', 'a gaggle'],
['giraffes', 'a tower'],
['gorillas', 'a band'],
['hippopotami', 'a bloat'],
['hyenas', 'a cackle'],
['jaguars', 'a shadow'],
['jellyfish', 'a smack'],
['kangaroos', 'a troop'],
['lemurs', 'a conspiracy'],
['leopards', 'a leap'],
['lions', 'a pride'],
['moles', 'a labor'],
['monkeys', 'a barrel'],
['mules', 'a pack'],
['otters', 'a family'],
['oxen', 'a team'],
['owls', 'a parliament'],
['parrots', 'a pandemonium'],
['pigs', 'a drift'],
['porcupines', 'a prickle'],
['rabbits', 'a herd'],
['rats', 'a colony'],
['ravens', 'an unkindness'],
['rhinoceroses', 'a crash'],
['sharks', 'a shiver'],
['skunks', 'a stench'],
['snakes', 'a nest'],
['squirrels', 'a dray'],
['stingrays', 'a fever'],
['swans', 'a bevy'],
['tigers', 'an ambush'],
['toads', 'a knot'],
['turkeys', 'a gang'],
['turtles', 'a bale'],
['weasels', 'a colony'],
['whales', 'a pod'],
['wolves', 'a pack'],
['zebras', 'a zeal'],
];
let animal = pickRandom(groups);
let sentence = `A group of ${animal[0]} is called ${animal[1]}.`;