Arqade is a question and answer site for passionate videogamers on all platforms. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Untrusted, I got to Level 7, where I can get the phone, and create my own JS function. I saw from the demo that I can change the colour! Great! So I figured I'd write a nested if... then statement, saying if I'm one colour, switch to the next! Apparently, that does not work.

I then tried to change my colour to white (#fff), thinking the collision check would accept white as all colours, and open the locks. What can I put in this function to change me as needed?

enter image description here

share|improve this question
Your image shows minimal effort. This is the if.. else if.. challenge. White over here will not help you. Try if green.. then red.. if red.. then yellow.. if yellow back to green. :-P – ヴァイシャリ Apr 10 '14 at 18:42
@ヴァイシャリ I realize it now, but I couldn't spoil it all in the question! – Canadian Luke Apr 10 '14 at 18:55
Heh I did not realize it was solved already. I tried to a one place Trusted walkthrough. They over rode me. (Pun intended) :-) – ヴァイシャリ Apr 10 '14 at 18:58
up vote 4 down vote accepted

You can get past all the gates using the code below:

else if(player.getColor()=='#ff0')

Basically, it makes it so every time you hit Q, you change to the color of the next gate.
Green -> Red -> Yellow -> Green


share|improve this answer
Aaarg! I was using a single equals sign! I'm posting my (much longer) answer as well, but that would definitely work! – Canadian Luke Apr 8 '14 at 19:44
@CanadianLuke I do that all the time too. Now I'll have to play this game the rest of the day. – Batophobia Apr 8 '14 at 19:47
I like the old-style games, like Candybox 1 and 2, as well – Canadian Luke Apr 8 '14 at 19:49
Exactly what I did xD – Darakath Apr 8 '14 at 20:51
Posting solutions – ヴァイシャリ Apr 10 '14 at 18:48

If you have solved it once, now you can play with it, improving the code. Thinking what else you can do, for example you can do something ugly and funny:

player.setPhoneCallback(function () {
  var i = 66;
  var callback = function(){
    player.setColor("#" + ((--i % 3) > 0 ? 'f' : '0') + ((i + 1) % 3 > 0 ? 'f' : '0') + '0')
  return callback;
(function doNothingHack(){ 

Also we can see that f00, ff0 and 0f0 can be represented as 100, 110, and 010, and this, as you can see are just 3 small integers (2, 3, 1) represented as binary. So modulo arithmetic, decimal to binary conversion then replace 1 with f, and we have another such solution.

share|improve this answer
Heh nice one. +1 – ヴァイシャリ Apr 10 '14 at 18:44

I decided to go ahead and post a few solutions of my own.


This one makes use of switch statements and saves each color as an object literal to improve readability and increase coding speed and efficiency:

var color = { 'green' : '#0f0',
              'red'   : '#f00',
              'yellow': '#ff0'};

switch(player.getColor()) {
        player.setColor(; break;

        player.setColor(color.yellow); break;

    case color.yellow:
        player.setColor(; break;


The default case at the end isn't necessary for that particular level, as the player's color is already green by default, but I decided to include it anyways for completion's sake.

Increment and modulo

This solution makes use of the increment operator ++ and the modulo operator %, making the code much, much shorter.

var colors = ['#0f0', '#f00', '#ff0'];
var i = 0;

player.setPhoneCallback(function() {
    player.setColor(colors[++i % 3]);


Since we can't add code outside the player.setPhoneCallback() method, it has become a bit hacky.

The idea behind this solution, is to define a color array which we will cycle through. For that, the increment and modulo operators are instrumental. For those who don't know: the modulo operator returns the rest of a division.

Since we don't want our variable i to be reset every time we use the phone, we have to redefine the phone method. Once we're done, we call player.setColor() to change our color. That part isn't necessary, but without it, we'd have to use the phone twice to change our color for the first time.

Once you understand the above code, we can shorten it even more:

if (!player.i) player.i = 0;
player.setColor(['#0f0', '#f00', '#ff0'][++player.i % 3]);
share|improve this answer
I wanted to post a solution using setInterval, but apparently the method is not allowed. Damn it... – Nolonar Apr 12 '14 at 22:00

Found the solution! I inserted the following code:

if (player.atLocation(24, 12)) {
if (player.atLocation(27, 12)) {
if (player.atLocation(30, 12)) {
if (player.atLocation(33, 12)) {
if (player.atLocation(35, 12)) {

If I am at the x, y coordinates, then it will execute that one colour change for me.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.