Task: The ELF Code

Welcome

Pasted image 20220904222911

Functions

Pasted image 20220904222920

Level 1

Pasted image 20220904222934

Level 2

Instructions

Pasted image 20220904223005

lever(0)

Pasted image 20220904223022

Solution

elf.moveLeft(6)
var sum = elf.get_lever(0) + 2
elf.pull_lever(sum)
elf.moveLeft(4)
elf.moveUp(10)

Level 3

Instructions

Program the elf to the end goal in no more than 4 lines of code and no more than 4 elf command/function execution statements in your code.

Solution

elf.moveTo(lollipop[0])
elf.moveTo(lollipop[1])
elf.moveTo(lollipop[2])
elf.moveUp(1)

Level 4

Instructions

Program the elf to the end goal in no more than 7 lines of code and no more than 6 elf command/function execution statements in your code.

Solution

for (var i = 0; i < 2; i++) elf.moveLeft(i + 1), elf.moveUp(11), elf.moveLeft(2), elf.moveDown(11);
elf.moveLeft(3)
elf.moveUp(10)

Level 5

Instructions

Program the elf to the end goal in no more than 10 lines of code and no more than 5 elf command/function execution statements in your code.

Munchkin #0 Objective

Pasted image 20220904223300

Solution

elf.moveTo(lollipop[1])
elf.moveTo(lollipop[0])
var str = elf.ask_munch(0)
var filtered = str.filter(function(r) {
  return parseInt(r) == r
});
elf.tell_munch(filtered)
elf.moveUp(2)

Level 6

Instructions

Note: There are two paths here for you to choose. CHoosing the lever may take more steps but might be easier to solve. Info: Program the elf to the end goal in no more than 15 lines of code and no more than 7 elf command/function execution statements in your code.

Munchkin #0 Objective

Pasted image 20220904223418

Lever #0 Objective

Pasted image 20220904223431

Solution

for (var i = 0; i < 4; i++) elf.moveTo(lollipop[i]);
elf.moveTo(munchkin[0])
console.log(elf.ask_munch(0))
var t = elf.ask_munch(0)
function getKeyByValue(object, value) {
  return Object.keys(object).find(key => object[key] === value);
}
var answer = getKeyByValue(t, "lollipop")
elf.tell_munch(answer)
elf.moveUp(2)

Level 7 - Yeeter Swirl

Pasted image 20220904223512