get help in general - we have more specialized help rooms here: https://gitter.im/FreeCodeCamp/home
function reverse(s) {
var o = [];
for (var i = 0, len = s.length; i <= len; i++)
o.push(s.charAt(len - i));
return o.join('');
}
.charAt
is the position of a character in a string.
so
s.charAt(len - i)
will push a character in s
, the string, at the calculated position of the string. That calculated position is equal to the value of the length of the s
minus i
.
var list = function(obj) {
for(var prop in obj) {
console.log(prop);
}
prop
do?
obj
means it is going trough objects?
prop
is the key that iterates through the array.
prop
know what to do if it can be anything?
function(obj)
we only call objects?
var friends = {};
friends.bill = {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ['One Microsoft Way','Redmond','WA','98052']
};
friends.steve = {
firstName: "Steve",
lastName: "Jobs",
number: "(408) 555-5555",
address: ['1 Infinite Loop','Cupertino','CA','95014']
};
var list = function(obj) {
for(var prop in obj) {
console.log(prop);
}
};
list(friends)
bill
steve
list(friends.steve)
it returns keys, but not their values. How do I call them both? Keys and their values.
console.log(prop + " : " + prop[0])
<!doctype html>
<html>
<head>
<link href="https://s3.amazonaws.com/codecademy-content/projects/bootstrap.min.css" rel="stylesheet" />
<link href='https://fonts.googleapis.com/css?family=Playfair+Display:400,400italic,700italic|Oswald' rel='stylesheet' type='text/css'>
<link href="css/main.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js"></script>
</head>
<body ng-app="PizzaPlanetApp">
<div class="header">
<h1><span>Pizza</span><span>Planet</span></h1>
</div>
<div class="main" ng-controller="MainController">
<div class="container">
<h1>Specials for {{ today | date }}</h1>
<h2>Appetizers</h2>
<div class="appetizers row" ng-repeat="appetizer in appetizers">
<div class="item col-md-9">
<h3 class="name">{{ appetizers.name }} </h3>
<p class="description">{{ appetizers.description }} </p>
</div>
<div class="price col-md-3">
<p class="price">{{ appetizers.price | currency }} </p>
</div>
</div>
<h2>Mains</h2>
<div class="mains row" ng-repeat="main in mains">
<div class="item col-md-9">
<h3 class="name">{{ mains.name }} </h3>
<p class="description">{{ mains.description }} </p>
</div>
<div class="price col-md-3">
<p class="price">{{ mains.price | currency }} </p>
</div>
</div>
<h2>Extras</h2>
<div class="extras row" ng-repeat="extra in extras">
<div class="item col-md-9">
<h3 class="name">{{ extras.name }} </h3>
<p class="description">{{ extras.description }} </p>
</div>
<div class="price col-md-3">
<p class="price">{{ extras.price | currency }} </p>
</div>
</div>
</div>
</div>
<div class="footer">
</div>
<!-- Modules -->
<script src="js/app.js"></script>
<!-- Controllers -->
<script src="js/controllers/MainController.js"></script>
</body>
</html>
app.controller('MainController', ['$scope', function($scope) {
$scope.today = new Date();
$scope.appetizers = [
{
name: 'Caprese',
description: 'Mozzarella, tomatoes, basil, balsmaic glaze.',
price: 4.95
},
{
name: 'Mozzarella Sticks',
description: 'Served with marinara sauce.',
price: 3.95
},
{
name: 'Bruschetta',
description: 'Grilled bread garlic, tomatoes, olive oil.',
price: 4.95
}
];
$scope.mains = [
{
name: 'Margherita',
description: 'Marinara sauce, mozzarella, fresh basil.',
price: 6.95
},
{
name: 'Pepperoni',
description: 'Pepperoni, marinara sauce, mozzarella, fresh oregano.',
price: 7.95
},
{
name: 'Rustica',
description: 'Marinara sauce, kalamata olives, roasted garlic, fresh oregano.',
price: 8.95
}
];
$scope.extras = [
{
name: 'Breadsticks',
description: 'Served with marinara sauce',
price: 4.95
},
{
name: 'Soup of the day',
description: 'Take a chance',
price: 4.95
},
{
name: 'Buffalo wings',
description: 'Feel the power of wings',
price: 6.95
}
];
}]);
var app = angular.module("PizzaPlanetApp", []);
for (main in mains) {
// I'd refer to each object in mains as main
main.property // not mains.property
}
<h2>Extras</h2>
<div class="extras row" ng-repeat="extra in extras">
<div class="item col-md-9">
<h3 class="name">{{ extra.name }} </h3>
<p class="description">{{ extra.description }} </p>
</div>
<div class="price col-md-3">
<p class="price">{{ extra.price | currency }} </p>
</div>
</div>
function DashInsert(str) {
var arr = str.split("");
for (var i = 0; i<arr.length; i++){
if (arr[i]==1||3||5||7||9){
if (arr[i]==arr[i+1]){
arr.splice(arr[i+1],0,"-");
}
}
}
var end = arr.join("");
return end;
}
function DashInsert(str) {
var arr = str.split("");
for (var i = 0; i<arr.length; i++){
if (arr[i]% 2!==0 ){
if (arr[i]===arr[i+1]){
arr.splice(arr[i+1],0,"-");
}
}
}
var end = arr.join("");
return end;
}
var arr = str.split("").map(function(i) {
return +i;
});