Terminal - Programming Concepts (The ELF C0DE)¶
Terminal¶
- Elf: Ribb Bonbowford
- Location: Dining Room
- Related to Objective:
The goal of this terminal game challenge is to teach you programming concepts and JavaScript. There are a lot of hints offered for this challenge that can be accessed in the hint section. When you click on the game console, you're greeted with an introduction to the game.
There are 8 levels for this game. At each level, you need to write JavaScript code to collect lollipops and finish the game. In the levels, there are different obstacles you need to avoid.
Level 1¶
Here is the code for level 1:
elf.moveLeft(10)
elf.moveUp(10)
Level 2 - Trigger The Yeeter¶
Here is the code for level 2:
elf.moveLeft(6)
var sum = elf.get_lever(0) + 2
elf.pull_lever(sum)
elf.moveLeft(4)
elf.moveUp(10)
Level 3 - Move to Loopiness¶
Here is the code for level 3:
for (var i = 0; i < 3; i++) {
elf.moveTo(lollipop[i])
}
elf.moveUp(1)
Level 4 - Up Down Loopiness¶
Here is the code for level 4:
for (var i = 0; i < 3; i++) {
elf.moveLeft(3)
elf.moveUp(11)
elf.moveLeft(3)
elf.moveDown(11)
}
Level 5 - Move To Madness¶
Here is the code for level 5:
elf.moveTo(lollipop[1]);
elf.moveTo(lollipop[0]);
var array = elf.ask_munch(0);
var result = array.filter(d => typeof d === 'number');
elf.tell_munch(result);
elf.moveUp(2);
Level 6 - Two Paths, Your Choice¶
Here is the code for level 6:
for (var i = 0; i < 4; i++) {
elf.moveTo(lollipop[i]);
}
elf.moveTo(munchkin[0]);
var JSON_Obj = elf.ask_munch(0);
for (key in JSON_Obj) {
if (JSON_Obj[key] == "lollipop") {
elf.tell_munch(key);
}
}
elf.moveUp(2);
This was the last level, but there are some bonus levels!!!
Level 7 - Yeeter Swirl (Bonus Level)¶
Here is the code for level 7:
var x = 0, y=0;
for (var i = 0; i < 2; i++) {
elf.moveDown(++x);
y=pull(y)
elf.moveLeft(++x);
y=pull(y)
elf.moveUp(++x);
y=pull(y)
elf.moveRight(++x);
y=pull(y)
}
elf.moveUp(2);
elf.moveLeft(4);
elf.tell_munch(TotalSum)
elf.moveUp(2);
function pull(l){
elf.pull_lever(l++);
return l;
}
function TotalSum(p1) {
var total = 0;
for (i in p1) {
p1[i] = p1[i].filter(d => typeof d === 'number');
p1[i]=p1[i].reduce((a, b) => a + b);
total += parseInt(p1[i]);
}
return total;
}
Compress the code so that it fits in the game console limits:
for(var x=0,y=0,i=0;2>i;i++)elf.moveDown(++x),y=pull(y),elf.moveLeft(++x),y=pull(y),elf.moveUp(++x),y=pull(y),elf.moveRight(++x),y=pull(y);elf.moveUp(2),elf.moveLeft(4),elf.tell_munch(TotalSum),elf.moveUp(2);function pull(a){return elf.pull_lever(a++),a}function TotalSum(a){var b=0;for(i in a)a[i]=a[i].filter(a=>"number"==typeof a),a[i]=a[i].reduce((c,a)=>c+a),b+=parseInt(a[i]);return b}
Level 8 - For Loop Finale (Bonus Level)¶
Here is the code for level 8:
var sum1 = 0;
elf.moveRight(1);
for (var i = 0; i < 6; i++) {
sum1 = movegetpull_lever(i, sum1);
}
function movegetpull_lever(p, s) {
var t_sum = 0;
t_sum = s + elf.get_lever(p);
elf.pull_lever(t_sum);
elf.moveUp(2);
var JSON_Obj = elf.ask_munch(0); //ask munch each time you pass the pit
elf.tell_munch(Munchkin_function); //tell munch each time you pass the pit, just incase he is waiting
if (p % 2 == 0) {
elf.moveLeft(3 + 2 * p);
} else {
elf.moveRight(3 + 2 * p);
}
return (t_sum);
}
function Munchkin_function(p1) {
for (array in p1) {
for (key in p1[array]) {
if (p1[array][key] == "lollipop") {
return key;
}
}
}
return 0;
}
After you complete the game you receive the following message:
Answer¶
The answers for this challenge are shown above.