Struggling with Code Combat and Javascript functions

Hi All,

Hope someone can offer some guidance. I have run the code through a Javascript validator for errors in the syntax and everything clears. The attack enemy works but the pick up coins doesn’t.

Here is the code:

// Peons are trying to steal your coins!
// Write a function to squash them before they can take your coins.

function pickUpCoins() {
    var coin = hero.findNearestItem();
    if(coin) {
        hero.moveXY(coin.pos.x, coin.pos.y);

// Write the attackEnemy function below.
// Find the nearest enemy and attack them if they exist!
function attackEnemy() {
    while (true) {
    var enemy = hero.findNearestEnemy();
    if (enemy) {
        // If there is an enemy, attack it!

while (true) {

while (true) {

Any help is appreciated.

I cleaned up your code for you. You can format code with three backticks above and below, like this:

function iLoveCode() {
return <3

Can you give some more context for this code? What is it that’s not working? Is there a link you can supply?

Sorry, but I don’t quite understand what you mean.

Well, there’s no way I can know just from looking at your code what it’s expected to do or why it might be failing. This isn’t a freeCodeCamp related problem, and I’ve never seen it before, so it would help to know where you found it and what it’s supposed to do.

Thanks for your response. I’ll just get back to the grind.