Console not working


I have a student making a simulated store in the console. When the game is run at full speed, the console doesn’t update and the prompt window keeps displaying over and over again. However, if he adds a break point and runs the code step by step, it works just fine. Can you please explain to me why the console does not stay current while his program is running?

Also as a quick follow up, I was going to recommend using the console for the create task because it is easier to create an algorithm that contains two other algorithms. Does anyone know if the main algorithm can be several event listeners? Otherwise using a while loop with a prompt seems to be the better option.

Thank you,

link from student w comment:

this code doesn’t work in the normal functionality of code studio, but it does work in the debug mode


Hrm. This is odd indeed. I have a suspicion about what is happening (and its devilish)** but I’ll have to pass this along the engineering team to see if there is a fix. Thanks for bringing this to our attention. Hopefully we can have an answer shortly.


** my guess is that the code interpreter is queuing up all the console output and waiting to actually dump it to the display until all of the prompts are done. You can actually enter purchase items until you run out of money - you just have to keep track in your head - and once you run out of money it flushes all of the output to the console. I know enough to know that we did weird things to make prompt work in app lab, but not enough to know a solution myself.

One thing you could do is have the student make it a lightweight event-driven app in which you click a button to purchase the next thing - all the output could remain in the console and all the input could still come from prompt. Basically, stick the while loop code inside an event handler and switch while(money >0) loop to if(money>0)

Here (note need to input two items before you see anything):

NERD TALK: FWIW while loops with JavaScript in web pages is always dicey whether it’s through app lab or not. Classic patterns of using a while loop to control user input flow tend to break down in a web environment where everything is supposed to be asynchronous and non-blocking. We tried to wrangle app lab to make some of those patterns do-able but it’s kind of like herding cats or maybe doing a deal with the devil. One of those two.


Thank you for looking into this. I completely understand what you are saying.

The main reason we were considering while loops with a prompt is because of the AP Performance Task. Students have to create an algorithm that contains 2 other algorithms. After going through the curriculum, students naturally want to make buttons and event listeners. My fear is that a series of event listeners is not considered an algorithm. If instead they make a while loop with a prompt that uses logic to delegate tasks, it will be easier to meet the PT requirement. I know that the while loop is not as nice and really not better programming, but the wording of the rubric seems to make it the better option.

Section 3: Applying Algorithms
“The selected algorithm integrates two or more commonly used or new algorithms, and integrates mathematical and/or logical concepts to create a new algorithm.”


Sure. Use loops just don’t mix with prompt :slight_smile:

I think the coin-flipping experiment in Unit 5 lesson 12 is good fodder for combining algorithms the way you are describing.

Also, don’t forget the turtle art from Unit 3. There are a lot of examples of combined algorithms and abstraction there.

Let’s just say I’m interested in how the “integrates two or more algorithms” thing is going to be interpreted. But suffice it to say that ultimately it’s going to come down to how well the student writes about it and justifies the two algorithms. As a low bar - I think in almost any scenario with a game that detects and processes a win/loss condition is candidate. Take this function from the color sleuth program:

function checkCorrect(buttonId) {
  console.log("checking: "+buttonId);
  if( buttonId == randButtonId ) {
  } else {
  checkGameOver();    <---- Algorithm!
  setBoard();          <---- Algorithm!
  switchPlayer();   <---- Algorithm!

checkCorrect is the essential algorithm for processing the game - it gets called with every mouse click. Inside it are all the sub-peices that make it up. I think a student could make a reasonable argument this is combining tow or more new algorithms that integrate logical concepts.

Naturally, I’ve been wondering how many examples we’re going to see that kill two birds with one stone: The abstraction also contains the algorithm, or vice versa. If you have loops and arrays, I think the job actually gets easier.