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

no average rating #5

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
52 changes: 52 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
angular.module("happyApp", [])

.controller("happyController", function ($scope){

$scope.allHappy = [];

// $scope.newHappy = {
// status : '',
// date : ''
// }

$scope.addHappy = function () {
$scope.date = new Date ();

$scope.allHappy.push({
status : $scope.emoticonSelected,
date : $scope.date
})

$scope.emoticonSelected = "";

console.log($scope.allHappy);
// angular.forEach(allHappy, function (){
// console.log(allHappy.status);
// })

// $scope.getAverage = function () {
// var averageArray = $scope.allHappy.map(function (string){
// if (string == 'happy') {
// return 1;
// } else if (string == 'ok') {
// return 0;
// } else { return -1};
// })

// var total = 0;

// total = averageArray.reduce (function (a,b) {
// return a + b;
// })

// var avgerage = total/averageArray.length;

// if (avgerage >= 0.5) {
// return 'Happy';
// } else if ( avgerage >= 0) {
// return 'Ok';
// } else { return 'Sad'};
// }

};
});
58 changes: 58 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html ng-app="happyApp">
<head>
<title>Document</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="app.js"></script>
<link href="http://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<link href='https://fonts.googleapis.com/css?family=Happy+Monkey' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body ng-controller="happyController">

<header>
<h1>HAPPYAPP</h1>
<h2>Generally average happiness over time, since 1986</h2>
</header>

<!-- <form ng-submit="addHappy()">
<input type="text" placeholder='Are you happy, ok, or sad..?' ng-model="newHappy.status">
<input type="submit" value="Save my Happiness">
</form> -->

<form novalidate ng-submit="addHappy()" name="myForm">
<label>
<input type="radio" ng-model="emoticonSelected" value="happy"/>
<img ng-src="https://cdn2.iconfinder.com/data/icons/windows-8-metro-style/512/happy.png">
</label>

<label>
<input type="radio" ng-model="emoticonSelected" value="ok"/>
<img ng-src="https://d30y9cdsu7xlg0.cloudfront.net/png/3061-200.png" alt="ok">
</label>

<label>
<input type="radio" ng-model="emoticonSelected" value="sad"/>
<img ng-src="https://cdn2.iconfinder.com/data/icons/social-productivity-line-art-1/128/face-sad-512.png">
</label>

<br/>

<input type="submit" value="Save my Happiness">
<div ng-if="emoticonSelected">Your'e emotional state is: {{ emoticonSelected }}</div>
</form>

<br/>

<ul ng-if="allHappy.length != 0" >
<li ng-repeat="happy in allHappy">
<strong> {{ happy.status }} - </strong>
{{ happy.date | date:'medium'}}
</li>
</ul>

<br/>
<h3 ng-if="allHappy.length > 0">Your average rating is: {{ getAverage() }}</h4>

</body>
</html>
21 changes: 21 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
body {
font-family: 'Happy Monkey', cursive;
text-align: center;
}

img {
height: 100px;
width: auto;
}

label > input{ /* HIDE RADIO */
visibility: hidden; /* Makes input not-clickable */
position: absolute; /* Remove input from document flow */
}
label > input + img{ /* IMAGE STYLES */
cursor:pointer;
border:2px solid transparent;
}
label > input:checked + img{ /* (RADIO CHECKED) IMAGE STYLES */
border:2px solid #f00;
}