Console logs first letter of myName


Completed the Course

So, I technically finished the course. However, my code doesn't actually work. I have looked through the forums and while now and can't seem to find anyone with this issue.
Issue: An array is logged to the console. But, the array only has logged three "M"s and not my whole name.
I've looked over the (correctly written) code on the Q&A for this topic and my code looks identical as far as I can see.
Please help. I really want to understand my code, why it works and why it doesn't work, not just pass the course.

/*jshint multistr:true */
var text = "Hi how are you! My name is Miranda\
A cool story is how I got my name. Since Miranda is pronouced the same in\
Spanish as it in in English my mother named me that so my\
Great grandmother could comfortably pronouce my name.";

var myName = "Miranda"
var hits = []

for (var i = 0; i < text.length; i++) {
  if (text[i] === "M") {
    for (var j = i; i > (myName.length + i); i++); {

if (hits.length === 0) {
  console.log("Your name wasn't found!");
} else {


Hi this line remove the ; at the end

for (var j = i; i > (myName.length + i); i++); <--

you could read more about that here..

Conditions, Blocks and Semicolons

If you want to understand how it work you could search on the forum there are many topic that explain how it work like these...

Search Text for Your Name further explanation needed

New j variable in challenge 6. “search text for my name”

Hope that could help you


I removed the semicolon and now the console logs that my name was not found at all.
Thank you for the links! I'll review them as soon as I am done with my lesson :smile:


Also here

for (var j = i; i > (myName.length + i); i++)

instead of i > (myName.length + i) change it to j < (myName.length + i)


That was it! Lol I had actually just change it after looking over one of the links you sent me (My lesson can wait!) when my browser gave me the notification. Thank you for your time and help :smiley:

for(i = 0; i < text.length; i++){
for(var j = i; j < (myName.length + i); j++){

Here is the correct block of code for anyone having the same issue :3


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