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 bear can "growl".
The next line of code prints the number 3
. The 3
is coming from dog.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 dog.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 noises = [
['antelope', 'snort'],
['badger', 'growl'],
['bat', 'screech'],
['bear', 'growl'],
['bee', 'buzz'],
['tiger', 'roar'],
['lion', 'roar'],
['jaguar', 'snarl'],
['leopard', 'growl'],
['calf', 'moo'],
['cat', 'meow'],
['chicken', 'cluck'],
['rooster', 'crow'],
['chinchilla', 'squeak'],
['cicada', 'chirp'],
['cow', 'moo'],
['cricket', 'chirp'],
['crow', 'caw'],
['deer', 'bleat'],
['wolf', 'howl'],
['dolphin', 'click'],
['donkey', 'bray'],
['duck', 'quack'],
['eagle', 'screech'],
['elephant', 'trumpet'],
['elk', 'bugle'],
['ferret', 'dook'],
['frog', 'croak'],
['toad', 'ribbit'],
['giraffe', 'bleat'],
['geese', 'honk'],
['grasshopper', 'chirp'],
['guinea pig', 'squeak'],
['hamster', 'squeak'],
['horse', 'neigh'],
['hippopotamus', 'growl'],
['hyena', 'laugh'],
['magpie', 'chatter'],
['mouse', 'squeak'],
['monkey', 'scream'],
['moose', 'bellow'],
['mosquito', 'buzz'],
['ox', 'moo'],
['owl', 'hoot'],
['parrot', 'squawk'],
['peacock', 'scream'],
['pig', 'oink'],
['pigeon', 'coo'],
['prairie dog', 'bark'],
['rabbit', 'squeak'],
['raccoon', 'trill'],
['raven', 'caw'],
['rhinoceros', 'bellow'],
['seal', 'bark'],
['sheep', 'baa'],
['goat', 'baa'],
['lamb', 'baa'],
['lark', 'warble'],
['wren', 'warble'],
['snake', 'hiss'],
['swan', 'cry'],
['tapir', 'squeak'],
['tarantula', 'hiss'],
['turkey', 'gobble'],
['vulture', 'scream'],
['walrus', 'groan'],
['whale', 'sing'],
['zebras', 'bray'],
];
let animal = pickRandom(noises);
let sentence = `A${animal[0][0] === 'e' ? 'n' : ''} ${animal[0]} can "${animal[1]}".`;