Build a Simon Game -- setTimeout help

I believe my problem lies in my teach(pattern) function. I just can’t seem to get setTimeout to do what I want.
Any insight into what I might be doing wrong is welcome and appreciated.

Here’s my pen.

You’re going to have to be more specific about “what you want.” What do you want it to do and when? What is it doing instead?

The more specific the question, the better the quantity and quality of the answers.


i think you have a problem here first … line 72 …
pad is a object so cant get into easyMode or newRound and then it goes to if pad === red but same problem pad is a object

if (pad === green) {
		easyMode = true;

i created variable padD = $(pad).attr.(‘id’) and changed if(padD = ‘0’) etc … but then i ran into error on this line 34 … tones[pad.attr(“id”)].play();

Thank you so much, John, for helping me sort this out! :thinking: I don’t think I created any objects to build this game. I did use pad as a local variable inside of different function definitions.

pad in your case is not a object you created look below … hope it helps

$(".colorpad").click(function() {
		var pad = $(this); 
/*so pad is the element you clicked on which is an object from the dom made up
of a lot of things .... you should console.log(pad)
you then do */
if (pad === green)
/*so pad is not what you are expecting it to be .... so thats why i did 
var padD = $(pad).attr('id) 
i now dont have a object i have a string which i can use to compare it to another string eg 
if(padD === '0') {
easyMode = true;

:see_no_evil:Oh, now I see.:hear_no_evil:
Thank you for spelling it out. Sorry for making you have to explain it again. I would never have been able to make that connection on my own.

Here’s what I’ve done:

  • I went through the $(".colorPad").click() function and did away with the pad variable and opted instead to just use $(this), and if($(this).attr("id") === green.attr("id"))

  • that change caused a problem with if ($(this).attr("id") === sequence[step]) because they are not of the same Type. As a quick fix, I opted to just use the less strict ==, and that feeeels sorta sloppy…??? I could’ve toString()'ed it. Are you aware if one method is favored over the other?

  • I also attempted to implement setTimeout() inside teach(pattern), but still no luck…thought???.

If you ignore that I still need to make Strict Mode a ‘thing’, It’s looking like I’m just one faulty setTimeout() away from a full function Simon Game. Thanks, man!!!