JavaScript Simplified / Chapter 34 Exercises

  • Index of exercises
  • Email me

1

2

3

4

5

6

7

8

9

10

Congratulations. You've aced all the exercises for this chapter.


To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to CodePen.


Are you ready to rate JavaScript Simplified? on Amazon?


Rate it on Amazon.

0,1,2,3,4,5,6,7,8,9

0

0

0

0

The method for finding the number of characters in a string is the same as the method for finding the number of elements in an ______. array array
Fill in the blank. let numberOfCharacters = someString_____; .length \.length
Code the first line of an if statement checks if the number of characters in the string assigned to the variable story is greater than 500. if (story.length > 500) { if\(story\.length>500\){
In a single line, display the number of characters in the string assigned to the variable sentence. alert(sentence.length); alert\(sentence\.length\);
  1. Code the first line of a for statement.
  2. Using a variable that represents a string, specify the number of characters in the string as the loop limiter, using <. Make up the name of the variable.
  3. Use i as the counter. Start at 0.
  4. Increment by 1.
for (let i = 0; i < paragraph.length; i++) { for\(leti=0;i<[a-z_$][a-zA-Z0-9_$]*\.length;i\+\+\){
Code an alert that concatenates the string "The number of characters is " with the number of characters in a string assigned to a variable. Make up the variable name. alert("The number of characters is " + name.length); alert\(•Thenumberofcharactersis•\+[a-z_$][a-zA-Z0-9_$]*\.length\);
Code an if statement. If the number of characters in a string assigned to a variable is more than 300, display an alert "Too much!" Make up the name of the variable. if (post.length > 300) {
  alert("Too much!");
}
if\([a-z_$][a-zA-Z0-9_$]*\.length>300\){[\r\n]alert\(•Toomuch!•\);[\r\n]}
If the length of str is less than 3, convert it to all-lowercase characters. if (str.length < 3) {
  str.toLowerCase();
}
if\(str\.length<3\){[\r\n]str\.toLowerCase\(\);[\r\n]}
  1. Assign a string to a variable.
  2. If the number of characters is more than 5 characters and less than 10 characters, display an alert that concatenates the string with " is a good length".
  3. If not, display an alert "out of range".
  4. Click the Result button (or, after revising, don't click, just wait).
  5. Wait a moment.
  6. If you've coded correctly, an alert will display one of the messages.
  7. Dismiss the alert by clicking OK.
  8. For help with this code, see Chapter 34 in the book.
  1. Assign a string to a variable.
  2. Targeting the index number of the last character using the length keyword, display the character in an alert.
  3. See if you can accomplish all of this in just two statements.
  4. Remember that the length property is 1-based, while an index is 0-based.
  5. Click the Result button (or, after revising, don't click, just wait).
  6. Wait a moment.
  7. If you've coded correctly, the an alert will display the last character.
  8. Dismiss the alert by clicking OK.
  9. For help with this code, see Chapter 34 in the book.