From ca9b88fd644f75950de238b104b8015d201e8bf9 Mon Sep 17 00:00:00 2001 From: Your NameNatalia Date: Fri, 3 Nov 2023 11:27:34 +0100 Subject: [PATCH 1/5] add task solution --- src/makeRobot.js | 55 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 4bcef1e45..7de2dcaee 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -38,7 +38,60 @@ * @return {Robot} */ function makeRobot(name, wheels, version) { - // write code here + const robot = { + name, + wheels, + version, + coords: { + x: 0, y: 0, + }, + get info() { + const robotName = `name: ${this.name}, `; + const robotInfo = `chip version: ${this.version}, wheels: ${this.wheels}`; + + return robotName + robotInfo; + }, + get location() { + return `${this.name}: x=${this.coords.x}, y=${this.coords.y}`; + }, + goForward(steps = 1) { + if (steps > 0) { + this.coords.y += steps; + } + + return this; + }, + goBack(steps = 1) { + if (steps > 0) { + this.coords.y -= steps; + } + + return this; + }, + goRight(steps = 1) { + if (steps > 0) { + this.coords.x += steps; + } + + return this; + }, + goLeft(steps = 1) { + if (steps > 0) { + this.coords.x -= steps; + } + + return this; + }, + evacuate() { + this.coords.x = 1400; + this.coords.y = 500; + + return this; + }, + + }; + + return robot; } module.exports = makeRobot; From a45b491960dbdb93f32998da408706baa2118bea Mon Sep 17 00:00:00 2001 From: Natalia Netzel <140259327+netzelnatalia@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:00:26 +0100 Subject: [PATCH 2/5] Update makeRobot.js --- src/makeRobot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 7de2dcaee..19c9a2c77 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -67,6 +67,7 @@ function makeRobot(name, wheels, version) { } return this; + }, goRight(steps = 1) { if (steps > 0) { @@ -86,7 +87,6 @@ function makeRobot(name, wheels, version) { this.coords.x = 1400; this.coords.y = 500; - return this; }, }; From 79eda03e60192386c474b39631a0c6d7db8ec6d0 Mon Sep 17 00:00:00 2001 From: Natalia Netzel <140259327+netzelnatalia@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:06:45 +0100 Subject: [PATCH 3/5] Update makeRobot.js --- src/makeRobot.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 19c9a2c77..42b42e2ad 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -43,16 +43,14 @@ function makeRobot(name, wheels, version) { wheels, version, coords: { - x: 0, y: 0, + x: 0, + y: 0, }, get info() { - const robotName = `name: ${this.name}, `; - const robotInfo = `chip version: ${this.version}, wheels: ${this.wheels}`; - - return robotName + robotInfo; + return 'name: ' + this.name + ', chip version: ' + this.version + ', wheels: ' + this.wheels; }, get location() { - return `${this.name}: x=${this.coords.x}, y=${this.coords.y}`; + return this.name + ': x=' + this.coords.x + ', y=' + this.coords.y; }, goForward(steps = 1) { if (steps > 0) { @@ -67,7 +65,6 @@ function makeRobot(name, wheels, version) { } return this; - }, goRight(steps = 1) { if (steps > 0) { @@ -86,9 +83,7 @@ function makeRobot(name, wheels, version) { evacuate() { this.coords.x = 1400; this.coords.y = 500; - }, - }; return robot; From 9e3f0950c8085607a5b878cd8f2401668f0f19e6 Mon Sep 17 00:00:00 2001 From: Natalia Netzel <140259327+netzelnatalia@users.noreply.github.com> Date: Fri, 3 Nov 2023 16:08:13 +0100 Subject: [PATCH 4/5] Update makeRobot.js --- src/makeRobot.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/makeRobot.js b/src/makeRobot.js index 42b42e2ad..577d59fe0 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -66,6 +66,7 @@ function makeRobot(name, wheels, version) { return this; }, + goRight(steps = 1) { if (steps > 0) { this.coords.x += steps; From b40d6f696b11a577155d045bec579e18d26e0167 Mon Sep 17 00:00:00 2001 From: Natalia Netzel <140259327+netzelnatalia@users.noreply.github.com> Date: Sat, 4 Nov 2023 15:07:47 +0100 Subject: [PATCH 5/5] Update makeRobot.js --- src/makeRobot.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/makeRobot.js b/src/makeRobot.js index 577d59fe0..1eb197b5e 100644 --- a/src/makeRobot.js +++ b/src/makeRobot.js @@ -47,7 +47,8 @@ function makeRobot(name, wheels, version) { y: 0, }, get info() { - return 'name: ' + this.name + ', chip version: ' + this.version + ', wheels: ' + this.wheels; + return 'name: ' + this.name + ', chip version: ' + + this.version + ', wheels: ' + this.wheels; }, get location() { return this.name + ': x=' + this.coords.x + ', y=' + this.coords.y;