Skip to main content
December 10, 2019
Answered

Use of conditionals IF

  • December 10, 2019
  • 1 reply
  • 365 views

Good morning, I'm doing an exercise and I want to use the conditional if, I did this code but it doesn't work for me, someone knows why it is.

 

Basically it is that when you click on an object it disappears and when all disappears that I display a message of retro feeding.

 

 


var _this = this;

_this.retro.visible = false;

_this.hit_fruta.on('click', function(){

 

_this.mc_fruta.visible = false;

_this.hit_fruta.visible = false;

SigEjer();

});

 

_this.hit_gato.on('click', function(){

 

_this.mc_pan.visible = false;

_this.hit_gato.visible = false;

SigEjer();

});

 

_this.hit_laptop.on('click', function(){

 

_this.mc_basura1.visible = false;

_this.hit_laptop.visible = false;

SigEjer();

});

 

_this.hit_consola.on('click', function(){

 

_this.mc_basura3.visible = false;

_this.hit_consola.visible = false;

SigEjer();

});

 

_this.hit_pelota.on('click', function(){

 

_this.mc_basura2.visible = false;

_this.hit_pelota.visible = false;

SigEjer();

});

 

_this.hit_paraguas.on('click', function(){

 

_this.mc_mesa.visible = false;

_this.hit_paraguas.visible = false;

SigEjer();

});

 

function SigEjer() {

if ( mc_mesa1._visible = false &&

mc_basura1._visible = false &&

mc_basura2._visible = false &&

mc_pan._visible = false &&

mc_fruta._visible = false &&

mc_basura3._visible = false

){

_this.retro.visible = true;

}

}

This topic has been closed for replies.
Correct answer JoãoCésar17023019

Hi.

 

Your code has at least three problems.

 

Inside of your SigEjer function body:

- You are referencing all objects in the if statement without _this (I suppose this is the correct context);

- There is no underscore in the visible property. It must be visible not _visible;

- You are using an assignment operator (=) in the if statement. You must use double equals (loose equality) or tripe equals (strict equality).

 

I hope this helps.

 

 

Regards,

JC

1 reply

JoãoCésar17023019
Community Expert
JoãoCésar17023019Community ExpertCorrect answer
Community Expert
December 10, 2019

Hi.

 

Your code has at least three problems.

 

Inside of your SigEjer function body:

- You are referencing all objects in the if statement without _this (I suppose this is the correct context);

- There is no underscore in the visible property. It must be visible not _visible;

- You are using an assignment operator (=) in the if statement. You must use double equals (loose equality) or tripe equals (strict equality).

 

I hope this helps.

 

 

Regards,

JC

December 10, 2019

Thank you very much, the advice worked for me.