File tree Expand file tree Collapse file tree 2 files changed +28
-11
lines changed Expand file tree Collapse file tree 2 files changed +28
-11
lines changed Original file line number Diff line number Diff line change 77
88 function LunchCheckController ( $scope ) {
99 $scope . name = "" ;
10-
11- $scope . check = function ( ) {
12- var numberOfTypes = $scope . name . split ( ',' ) ;
13- if ( numberOfTypes . length = 0 )
14- $scope . message = "Please enter data first" ;
15- else if ( numberOfTypes . length <= 3 )
16- $scope . message = "Enjoy!" ;
10+ $scope . messages = "" ;
11+
12+ $scope . check = function ( ) {
13+
14+ var input = $scope . name ;
15+ var numberOfTypes = input . split ( "," ) ;
16+ var numberOfItems = 0 ;
17+ console . log ( numberOfTypes . length ) ;
18+ for ( var i = 0 ; i < numberOfTypes . length ; i ++ ) {
19+ if ( numberOfTypes [ i ] . trim ( ) != "" ) {
20+ numberOfItems ++ ;
21+ }
22+ }
23+
24+ if ( input . trim ( ) == 0 )
25+ {
26+ $scope . messages = "Please enter data first" ;
27+ }
28+ else if ( numberOfItems <= 3 )
29+ {
30+ $scope . messages = "Enjoy!" ;
31+ }
1732 else
18- $scope . message = "Too much!" ;
33+ {
34+ $scope . messages = "Too much!" ;
35+ }
1936 } ;
2037
2138 } ;
Original file line number Diff line number Diff line change @@ -21,10 +21,10 @@ <h1>Lunch Checker</h1>
2121 ng-model = "name ">
2222 </ div >
2323 < div class ="form-group ">
24- < button class ="btn btn-default " ng-click ="check "> Check If Too Much</ button >
24+ < button class ="btn btn-default " ng-click ="check(); "> Check If Too Much</ button >
2525 </ div >
26- < div class ="form-group message " ng-bind =" message " >
27- <!-- Your message can go here. -->
26+ < div class ="form-group message ">
27+ {{messages}}
2828 </ div >
2929 </ div >
3030 </ div >
You can’t perform that action at this time.
0 commit comments