"7. Victory!" Is this solution the best?



Hello everyone!
I know it is not a big deal, but I feel that it's possible to do it in a different and better way... I am just curious. Is this the best way? Do I need to make those "toLowerCase" or is there any better solution? If you have any more suggestions or you find any problem, please tell me!
Thank you!

var text = "asfiih isif sfij fa sfhisf ssff Fabio you Fatio sf ggdsdg FABIO See you fabio";
var myNamePrompt = prompt("What's your name?");
var myName = myNamePrompt.toLowerCase();
var hits = [];

for ( var i = 0; i < text.length; i++) {
    if (text[i] === myName[0]||(myName[0].toLowerCase())) {
        var preMatches = text.substring(i,(i+myName.length));
        var matches = preMatches.toLowerCase();
        if (matches === myName) {

var stringHits = hits.join(", ");

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


You can also try as a test to uses regular expressions to solve this?


Oh, I don't know what regular expressions are but I will look into it! Thank you so much!


its so much hardy , b i can't realize the code .


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