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

including bonus #6

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
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var app = angular.module('HappyApp',[])
99 changes: 99 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<!DOCTYPE html>
<html ng-app="HappyApp">
<head>
<meta charset="UTF-8">
<title>HappyApp</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,800' rel='stylesheet' type='text/css'>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="app.js"></script>
<script src="js/data.js"></script>
<style>
body{
font-family: 'Open Sans', sans-serif;
text-align:center;
}
h1{
font-size:60px;
}
input[type=submit]{
background:black;
color:white;
padding:10px 20px;
border:none;
border-radius:5px;
margin-top:50px;
font-size:15px;
letter-spacing: 1px;
}
input[type=radio]{
-webkit-appearance:none;
appearance:none;
}
.label-selector{
font-size:40px;
font-weight:800;
cursor:pointer;
padding-bottom:10px;
padding-left:20px;
}
.label-selector:hover{
border:2px solid black;
}
div.emotion{
font-weight:800;
font-size:50px;
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-ms-transform: rotate(90deg);
-o-transform: rotate(90deg);
transform: rotate(90deg);
}
.circle{
border-radius:30px;
height:50px;
width:50px;
border:2px solid black;
font-size:35px;
margin-left:18px;
}
.oneDay{
width:100px;
display:inline-block;
text-align:center;
}
.question{
border:3px solid black;
padding:50px;
margin:50px auto;
width:50%;
border-radius:5px;
}
</style>
</head>
<body>
<h1>HAPPYAPP</h1>
<section ng-controller="HappinessController">
<div ng-if="all.length != 0" class="day">
<div ng-repeat="day in all" class="oneDay">
<div class="emotion">{{displayRating[day.rating]}}</div><div class="circle">{{day.day}}</div>
</div>
</div>
<div class="question">
<h2>How's your happiness today?</h2>
<p>Your average happiness: {{average}} </p>
<p>Click one to pick it. then save.</p>
<form ng-submit="add()">
<label ng-repeat="rate in rating" for="{{rate}}" class="label-selector">
{{displayRating[rate]}}
<input type="radio"
ng-model="newRating.rating"
ng-value="rate"
id="{{rate}}"
name="{{rate}}">
</label>
<br/><input type="submit" value="Save My Happiness">
</form>
</div>
</section>
</body>
</html>
29 changes: 29 additions & 0 deletions js/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
app.controller('HappinessController', HappinessController);

function HappinessController($scope){
$scope.rating = ['sad','mild','happy'];
$scope.displayRating ={
sad: ':-(',
mild: ':-|',
happy: ':-)'
}
$scope.score = {
sad: 1,
mild: 2,
happy: 3
}

$scope.newRating = { rating: 'mild'}

$scope.all = [];
$scope.average = 0;

$scope.add = function(){
var newDay = {
day: $scope.all.length + 1,
rating: $scope.newRating.rating
}
$scope.average = ($scope.average*(newDay.day-1) + $scope.score[newDay.rating])/ newDay.day
$scope.all.push({day: $scope.all.length+1, rating: $scope.newRating.rating})
}
}