Burlbole grove(JAVA) (solved)


#1

Hello, community, been stuck on this SUBJ level, googled, and tried youtube, nothing helped.
Will break it into two parts, function and execution.
First of all, there was no lesson on ‘NOT operator’, but from googling I’ve realized in real JAVA it’s" !="
when I’ve tried using != gives me mistakes, looked up in hints, and there just only “!” sign

so here’s my function logic:

// if there's no !taget return false 
//but if there's target beast burl, retuns false (don't touch him)    
//otherwise if something else returning true
function shouldAttack(target) {
    if (!target) {
        return false;
   
    if (taget.type == "burl");
        return false;
    
    } else {
        return true;
    }
}

tnx for your replies


Burlbole Grove - adventurer feedback
#2

There is a typo on Line 5 (target, not taget :wink:), as well as an incorrectly placed semicolon. Where is the identifier? :wink:

Other than that, it looks good :slight_smile:


#3

tnx for your reply, I guess I’m too tired for today lol, already did like 20 lvl in forest, there was also mistakes with {}
so what’s the different between “!” and “!=” operators?


#4

!= is the Python version (not sure if it appears in others?)


#5

that it’s a bug, because in javascript we use !=


#6
// not equal:  !=
// usage: compares the operands on both sides of the "!="
//        and returns true if the operands are not equal to each other;
//        else, it returns false
if ( 1 != 2 ) {
    hero.say("1 does not equal 2");
}

// not:  !
// usage: if the following expression is true, the ! operator returns false;
//        if the following expression is false, the ! operator returns true.
if ( !( 1 != 2 ) ) {    // this is basically: if ( !(true) )
    hero.say("the hero won't say this");
}

Note that the != operator compares two values on both sides.
The ! operator only uses a true or false value to the right side.

More on the not operator
if ( !true ) { } // !true evaluates to false

if ( !false ) { } // !false evaluates to true