Why Does This Buzzer Stop?

A student submitted this code and I did not expect the OFF selection to work. I was surprised when it did. I remixed it to add some debugging messages… Can anyone explain this?

Link to the project or level: Here is the project
What I expect to happen: [I expect the buzzer to turn on when ON is selected, but I do not expect the buzzer to turn off when OFF is selected.]
What actually happens: [the buzzer turns off]
What I’ve tried: [I added some console.log messages that seem to confirm that the theramin variable does NOT equal “of”, but the buzzer turns off.]

Hello @jwilson25

Seems like you have been testing for of when your actual value should be off to turn off the buzzer i’ve changed your code a bit to have it work without the board

//1) Create an event to continuously check the lightSensor
onEvent("thereminScreen", "click", function() {
  //2) Get the value from the dropdown and store it in a variable
  var theramin = getProperty("theraminDropdown", "value");
  console.log("theramin: '" + theramin + "'") ;
  console.log(theramin == "off");
  //3) If the value is "on": play the buzzer using the light sensor's value
  if (theramin == "on") {
    buzzer.frequency(lightSensor.value, 100);
  }
  //4) If the value is "off": stop the buzzer
  if (theramin == "off") {
  console.log(">> " + String(theramin == "off"));
   buzzer.stop();
  }
});

if this doesn’t work let me know you may need to change back the event to the board listener you were

Also if you want the buzzer to stay on for longer Code.org Tool Documentation seems to be the best answer I’m not sure if the board is getting interrupted since it may only be able to play one pitch at a time so if there is a buzzer.isPlaying boolean function possibly include that as an and or return statement to prevent further logic in the function from executing