Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
Binary file added happy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html ng-app="happyapp">
<head>
<meta charset="utf-8">
<title>HappyApp</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script src="js/app.js"></script>
</head>

<body class="text-center">
<section ng-controller="HappyController">
<h1>HAPPYAPP</h1>
<p>General average happiness over time since 1986</p>
<h4> History </h4>
<ul>
<li ng-repeat='n in allEmotion track by $index' style="Display: inline">Day {{$index}}: {{ n }} </li>
</ul>
<h4 ng-if="allEmotion.length > 0">Average rating: {{ getAvg() }}</h4>
<hr>
<div class="container well">
<form id='add-emotion' ng-submit="addNewEmotion()" class="form form-horizontal">
<input type="radio" value='Happy' ng-model="dailyemotion"><img src="happy.png" alt="Happy">
<input type="radio" value='OK' ng-model="dailyemotion"><img src="ok.png" alt="OK">
<input type="radio" value='Unhappy' ng-model="dailyemotion" ><img src="unhappy.png" alt="Unhappy">
<br>
<br>
<input type="submit" value="Save My Happiness" class="btn btn-default">
</form>
</div>
</section>

</body>
</html>
34 changes: 34 additions & 0 deletions js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
angular.module('happyapp', [])
.controller('HappyController', HappyController)


function HappyController($scope){
$scope.allEmotion = [];

$scope.getAvg = function(){
var eArr =$scope.allEmotion.map(function(str){
if (str =='Happy'){
return 1;
} else if (str == 'OK'){
return 0;
} else { return -1};
})
var total = 0;
total = eArr.reduce(function(a,b){
return a+b
})
var avg = total / eArr.length;
if (avg>=0.5){
return 'Happy';
} else if ( avg >=0){
return 'OK';
} else {return 'Unhappy'};
}

$scope.addNewEmotion = function (){
$scope.allEmotion.push($scope.dailyemotion);
$scope.dailyemotion = '';
}
}


Binary file added ok.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added unhappy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.