On part 5/9 JavaScript, the results should be 25, not 30. There is not 30 chatacters in the sentence "Teaching the world how to code." Am I not right?


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>

```

Replace this line with your code.

<do not remove the three backticks above>

#2
   (8)    (3)  (5)  (3)(2) (4)
“Teaching the world how to code.”
         ^   ^     ^   ^  ^    ^
         |   |     |   |  |    |
         1   2     3   4  5    6
Teaching =  8
the      =  3
world    =  5
how      =  3
to       =  2
code     =  4
        (+)===
sub-tot-1= 25

<space-chars>  =  5
<period dot .> =  1
              (+)===
sub-tot-2         6

Total of 31

#3

As @leonhard.wettengmx.n showed you, all characters count within a string, including punctuation and whitespaces.


#4

@mario71,

The reason of your confusion:
We as humans always start our counting at 1…
In most machine-languages the counting starts at 0 zero

Thus:
If we as human count the =characters= in the string
“Teaching the world how to code.” we =count= 31-characters
but
if we look at the length-property of the string using
“Teaching the world how to code.”.length
we will see the number-Value 30


#5

Agreed and thanks for the visual calculation on above post.

But @leonhard.wettengmx.n,

console.log('Teaching the world how to code.'.length);

still yielded 31 characters. Printing in console : 31


Maybe you’re trying to say the index positioning of 31?


var testingString = 'Teaching the world how to code.';

console.log('Teaching the world how to code.'.length);
console.log(testingString[31]);

console.log(testingString[31]); will yield undefined. Because the last character is placed between index [30] and index [31].

The computer counts index position start at[0]. So if you want to find the dot . at the end.
It should be testingString[30]

console.log(testingString[30]); 

Printing:

.

#6

spaces count as characters you know


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.