The code doesn't work


Hi everyone!
I reach the end of the exercise but then the console prints []

var text = "My name is Giada\  Mio padre ha scelto il nome Giada\ anche se mi dovevo chiamare Elisa";
var myName = "Giada";
var hits = [];
for (var i=0; i<text.length; i++) {
    if (text[i] === myName[0]) {
        for (var j=i; j<i+myName.length; j++) {
if (hits.length = 0) {
    console.log("Your name wasn't found!")}
else {

What am I doing wrong?


if (hits.length = 0) {

we use = for assignment if we want to check whether two values are equal or not we should use ==or ===


Thanks, now the code works!


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