Animal Noises explainer


#1

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()