-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
52 lines (45 loc) · 1.39 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
(function () {
'use strict';
angular.module('LunchCheck',[])
.controller('LunchCheckController',LunchCheckController );
LunchCheckController.$inject = ['$scope','$filter'];
function LunchCheckController($scope,$filter){
$scope.message;
$scope.listOfFoods = "";
$scope.color = "";
$scope.displayMessage = function(){
var finalmessage = "";
var numOfArguments = splitString($scope.listOfFoods,",")
if ( numOfArguments > 3 ) {
finalmessage = "too many";
$scope.color = "green";
}
else if (numOfArguments <= 3 && numOfArguments > 0) {
finalmessage = "enjoy";
$scope.color = "green";
}
else {
finalmessage = "not enough arguments";
$scope.color = "red";
}
$scope.message = finalmessage;
function splitString(stringToSplit, separator) {
var arrayOfStrings = stringToSplit.split(separator);
if (arrayOfStrings.length == 1 && arrayOfStrings[0].length == 0 )
return 0;
else
return arrayOfStrings.length - findEmptyFields(arrayOfStrings);
};
function findEmptyFields(array)
{
var counter = 0;
for (var i = 0; i < array.length; i++) {
if (array[i].trim() == "") {
counter++;
}
}
return counter;
}
}
}
})();