Your"if"statement


#1


https://www.codecademy.com/zh/courses/javascript-beginner-en-XEDZA/0/4?curriculum_id=506324b3a7dffd00020bf661#


i don't know where i did wrong in my code, can anyone else help me figure it out?


/*jshint multistr:true */

var text = "Hey, how are you doing? My name is Allen.";
var myName = "Allen";
var hits = [];  
for ( i = 0; i < text.length; i ++) {
    console.log(text);
    if ( text [i] ==="A") {
        console.log("NICE JOB!!!");} else {
         return "Shit!!!";}
}


#2

here:

 return "Shit!!!";}

don't use return, return can only be used in functions. You don't have a function


#3

i have already changed it to ""console.log", but it seems like that's not the problem, cause i was still stuck at this exercise.


#4

This is your code,

for ( i = 0; i < text.length; i ++) {
       console.log(text);
    if ( text [i] ==="A") {
        console.log("NICE JOB!!!");
    } else {
        return "Shit!!!";
}
}

Instructions:

Add your if statement in the body of your for loop. It should check to see whether the current letter is equal to the first letter of your name. (Capitalization counts!)

There's no need to put anything between the {}s of your if just yet.

No console.log needed, anywhere, for this specific exercise.


#5

here:

text [i]

you can't have a space between text and [i]


#6

thanks a lot, yeah, i probably should remove the console.log code better.


#7

thanks a lot, yeah, that really affects the code, finally get through it, appreciate!


#8

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