TypeScript => APCSP PseudoCode Generator

JavaScript


let name = window.prompt("What is your name?");
if (name === 'Alice') {
window.alert('Welcome to Wonderland!');
} else {
window.alert('Why hello, ' + name + '!');
}


Line 1: name ← INPUT("What is your name?")
Line 2: IF name = "Alice" THEN 
Line 3: {
Line 4:   DISPLAY("Welcome to Wonderland!")
Line 5: }  ELSE
Line 6: {
Line 7:   DISPLAY(CONCAT(CONCAT("Why hello, ", name), "!"))
Line 8: }

How to Use

Just type JavaScript in the JavaScript side, and you should see code appear on the right. If I implemented the syntax you're using (which should be most syntax), it should show up translated into APCSP code.

We also support some APCSP functions, such as RANDOM, DISPLAY, and INPUT.

I've also inputted APCSP style robot code, which you can access by calling methods such as ROTATE_RIGHT or MOVE_FORWARD or the more JS-like alternatives I've put in which are forward(), right(), left(), etc.

For problems, try typing:

  • PROBLEM_1()
  • PROBLEM_2()
  • PROBLEM_3()
  • etc.

The full list of robot functions is:

  • forward() or MOVE_FORWARD()
  • left() or ROTATE_LEFT()
  • right() or ROTATE_RIGHT()
  • canMove() or CAN_MOVE()

Some structures, such as objects, aren't supported in the APCSP syntax, so YMMV.

If you want to try running the code, I recommend using window.prompt (for input) and window.alert (for DISPLAY) so you can see the results when you click the "run" button (you have to reset to run again, so that we destroy and re-create an iFrame to give you a fresh JavaScript context to run your code in).

You can also use console.log for DISPLAY but you'll have to pop open an inspector to see your log statements and I'll warn you I probably spammed the inspector with my own debug messages.

If you want to be impressed with my overachieving in creating this tools, take some of the list methods for a spin.

For example, the following code fragments should work.


let fruits = ['apple','pear','persimmon','banana'];
let pfruits = fruits.filter(fruit => fruit[0]=='p');

List methods I've implemented include:

  • forEach
  • map
  • filter
  • some
  • includes
  • find