forked from rocketacademy/basics-github-practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
21 lines (19 loc) · 717 Bytes
/
script.js
File metadata and controls
21 lines (19 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Please declare functions and variables above where they are used.
var jerrysPosition = 0;
var tomsPosition = 0;
var getRandomNumFrom1To10 = function () {
var randomDecimal = Math.random() * 10;
var randomInteger = Math.floor(randomDecimal) + 1;
return randomInteger;
};
var main = function (input) {
var myOutputValue = 'Tom did not catch Jerry. ';
var jerrysNextPosition = getRandomNumFrom1To10();
jerrysPosition += jerrysNextPosition;
tomsPosition += parseInt(input);
if (jerrysPosition == tomsPosition) {
myOutputValue = 'Tom has caught Jerry! ';
}
myOutputValue += 'Total distance of Jerry = ' + jerrysPosition + ' Total distance of Tom = ' + tomsPosition;
return myOutputValue;
};