AP Lab Switch not working?


I wrote a program to do conversions from decimal to binary, hex,octal and vice versa last year while my students were engaged in the AP performance tasks for AP CSP. I tried to run it and found that it no longer works as designed. After placing some console log statements in various functions I found that the switch statement no longer works. I replaced my switches with if then elses and it works. I am curious why this changed? It looks like the switch block was taken out of the toolbox.


Hm, I’ve never noticed the switch statement in there, but maybe it’s because I never used it as part of the course (either because it wasn’t in the curriculum or I didn’t get to that part of the curriculum).

I’ll forward your question to code.org staff.


Hi Anthony,

Sorry, I noticed this post this morning and brought it up with our engineers. Switch statements should work, but, guess what? You exposed a bug, but it wasn’t our fault! Our engineer discovered something in our code interpreter - a 3rd party had implemented some logic incorrectly. Our engineer fixed it, and it should go out with tomorrow’s deploy.

Also, I don’t think switch statements were ever in our code toolbox. You can use them because they are part of javascript. And they should work - and they actually do now in most cases, except for what our engineer found. If you’re interested here was the code he used to reveal the problem:

function doSwitch(x) {
  switch(x) {
    case 1:
      console.log('case 1');
    case 2:
      console.log('case 2');
    case 3:
      console.log('case 3');
    case 4:
      console.log('case 4');
      console.log('case 5');

// This works
// Expected&Actual: case 3

// Either loop or switch is broken
// Expected: case 1 case 2 case 3 case 4 case 5
// Actual  : case 1 case 1 case 1 case 1 case 1
for (var i = 1; i <= 5; i++) {

Anyway, thanks for the find. But switch statements should work.