What did i do wrong? (As a result im getting the number 4)



It displays only the Number 4 instead of the Name Olex. Can anyone help me with it? I went like 6 times through the code but can not find the mistake. Theres also no Error message. only that it displays me the number 4 on the console.
Or is the number 4 right since it is the 4th word in the text variable?

/*jshint multistr:true */

var text = "Alex Slex Dlex Olex";
var myName = "Olex";
var hits = [];

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


If i console.print(hits) i get [ 'O', 'l', 'e', 'x' ]. So i think the code above is correct. Sry for the dumb question above :/...Is there a way to get it without the comma and mybe as one word within ' ' ?


hits.join('') will work (inside of join use either two single quotes or two double quotes)

Reference: w3schools - https://www.w3schools.com/jsref/jsref_join.asp


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