Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions week3/final/robot-text/Hamza.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello teacher could you accept my pull request
42 changes: 25 additions & 17 deletions week3/final/robot-text/robot.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
(function () {
((function () {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need these extra parentheses. As I explained earlier this is sufficient:

(function () {
    // all your other code
})();

'use strict';

const board = [
['T', 'T', '.', 'F'],
['T', '.', '.', '.'],
['.', '.', '.', '.'],
['R', '.', '.', 'W']
['.', '.', '.', '.','.'],
['.', '.', '.', '.','.'],
['R', '.', '.', '.','F'],
['.', 'A', 'A', 'A','.'],
['.', '.', '.', '.','.']
];

const robot = {
x: 0,
y: 0,
dir: 'up',
y: 2,
dir: 'down',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initial direction of the robot in the example is 'right'.

};

let flagReached = false;
let moves = 0;
let appleEaten = false;
let applesEatenNum = 0;

board.reverse();

Expand All @@ -37,7 +38,11 @@
console.log(line);
}
if (flagReached) {
console.log('\nHurray! Flag reached in ' + moves + ' steps!');
console.log('\nHurray! Flag reached in ' + moves + ' steps!' + ' and i did eat ' + applesEatenNum + ' apples' );
}
if(appleEaten){
console.log('Yum') ;

}
}

Expand All @@ -62,14 +67,19 @@

const cellContents = board[y][x];

if (cellContents === '.' || cellContents === 'F') {
if (cellContents === '.' || cellContents === 'F' || cellContents === 'A') {
board[robot.y][robot.x] = trailIndicators[robot.dir];
robot.x = x;
robot.y = y;
board[y][x] = 'R';

if (cellContents === 'F') {
flagReached = true;
}
if(cellContents === 'A'){
applesEatenNum+=1;
appleEaten = true;
}
}

moves += 1;
Expand All @@ -95,16 +105,14 @@
break;
}
}

render();

move();
turn('right');
turn('left');
move();
move();
move();
move();
turn('left');
move();
move();
move();

})();
}()));