Code should be right but ERROR unexpected end of input


#1

var myName = "Bianx";
var hits = [];

for (var i = 0; i <= text.length; i++) {
if(text[i] === "B") {

//(its alll indented in my console)


#2

will exceed the range of the string. Should be,

    i < text.length;

The above is just a snippet, right?


#3

//I tried using that too. Here is the current code. I've copied all of the code from this section here.

var text = "Bianx schedule. Bianx.";

var myName = "Bianx";
var hits = [];

for (var i = 0; i < text.length; i++) {
if(text[i] === "B") {


#4

Suggest go back to the first lesson and review the example.


#5

Thank you for the response. I did that too. Are you suggesting the code or syntax are wrong? I'll review again just in case I am missing something.


#6

We cannot see enough of your code to draw any conclusions. That's why I suggested examining the sample created by the author. Post your entire program, please, if you are still having trouble.


#7

Thanks for the help. added } to code block and ran smoothly.

Here is correct syntax for future users at this part of lesson:

Question 4 Searching for your name, if statement.

var myName = "Bianx";
var hits = [];

for (var i = 0; i < text.length; i++) {
} if(text[i] === myName[0]) {
}


#8

should be inside the for statement code body.

/*jshint multistr:true */
var text, myName, hits;
text = "In diam diam, molestie Roy nec ullamcorper id, condimentum \
id mauris. Sed lacinia libero Roy vitae massa hendrerit vitae porttitor \
mauris porta. Praesent Roy dapibus vestibulum semper. Aenean posuere \
suscipit accumsan. Phasellus ac arcu Roy arcu. Phasellus sodales \
venenatis mollis. Fusce dignissim Roy mollis tortor sed fermentum. \
Pellentesque egestas, Roy mi in accumsan tempor, justo felis.";
myName = "Roy";
hits = [];
for (i=0; i<text.length; i++) {
    if (text[i]===myName[0]) {
        
    }
}