cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Codding a robot

Michael_koroma
Making moves

Console.log("Hello world");

console.log("Initializing robot game...");

// Step 1: Create the robot object
let robot = {
name: "Robo-ING",
x: 0, // starting position X
y: 0, // starting position Y
move: function(direction) {
if(direction === "up") this.y += 1;
else if(direction === "down") this.y -= 1;
else if(direction === "left") this.x -= 1;
else if(direction === "right") this.x += 1;
console.log(`${this.name} moved ${direction} to (${this.x}, ${this.y})`);
}
};

console.log("Robot created:", robot.name);

1 REPLY 1

Michael_koroma
Making moves

console.log("Initializing robot game...");

// Step 1: Create the robot object
let robot = {
name: "Robo-ING",
x: 0, // starting position X
y: 0, // starting position Y
move: function(direction) {
if(direction === "up") this.y += 1;
else if(direction === "down") this.y -= 1;
else if(direction === "left") this.x -= 1;
else if(direction === "right") this.x += 1;
console.log(`${this.name} moved ${direction} to (${this.x}, ${this.y})`);
}
};

console.log("Robot created:", robot.name);