diff --git a/week3/final/robot-text/ Hello teacher Could you please accept my pull request b/week3/final/robot-text/ Hello teacher Could you please accept my pull request new file mode 100644 index 0000000..e69de29 diff --git a/week3/final/robot-text/Hamza.md b/week3/final/robot-text/Hamza.md new file mode 100644 index 0000000..cfcdbed --- /dev/null +++ b/week3/final/robot-text/Hamza.md @@ -0,0 +1 @@ +hello teacher could you accept my pull request diff --git a/week3/final/robot-text/robot.js b/week3/final/robot-text/robot.js index f2eb96d..83852fd 100644 --- a/week3/final/robot-text/robot.js +++ b/week3/final/robot-text/robot.js @@ -1,21 +1,22 @@ -(function () { +((function () { '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', }; - let flagReached = false; let moves = 0; + let appleEaten = false; + let applesEatenNum = 0; board.reverse(); @@ -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') ; + } } @@ -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; @@ -95,16 +105,14 @@ break; } } - render(); - move(); - turn('right'); + turn('left'); move(); move(); move(); + move(); turn('left'); - move(); - move(); + move(); -})(); +}()));