Index - JS: 1. Try It Out - Hello
Index - JS: 1. Try It Out - Hello
index.js
//write your code here
index.html
<!-- Hmtl -->
<html>
<head>
<script src="lib/angularjs/angular.min.js"></script>
<script src="lib/angularjs/angular-mocks.js"></script>
<script src="index.js" type="text/javascript"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<input ng-model="first_name"><br><br>
<input ng-model="last_name"><br><br>
</div>
</body>
</html>
Index.js
// Add your code here
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.number1 = 100;
$scope.number2 = 11;
$scope.odd_even = function(result) {
if (result % 2 === 0) {
return "even";
} else {
return "odd";
}
};
});
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular-
route.min.js"></script>
<script src="index.js"></script>
</head>
</div>
<br />
<div class="search_drop_down">
<select id="month" class="select select-styled" >
<option value="hide">-- Brand --</option>
<option ng-repeat="pdt in products" >{{pdt.brand}}</option>
</select>
</div>
<div class="single_2">
<div class="prod_desc">
<span class="pdt_name">{{pdt.name}}</span>
<div class="pdt_details_2_col">
<span class="brand">Brand</span>
<span class="brand_name">{{pdt.brand}}</span>
</div>
<div class="pdt_details_2_col">
<span class="brand">Price</span>
<span class="brand_name">{{pdt.price}}</span>
</div>
</div>
</div>
<div class="single_3">
<div class="quantity_sec">
<label>Quantity</label>
<br>
<input placeholder="Quantity" type="number" ng-model="pdt.quantity" >
</div>
</div>
<div class="single_4">
<input type="image" src="img/greyCart.png" alt="Submit" width="48" height="48" ng-
show="pdt.quantity<1?true:false" />
<input type="image" src="img/orangeCart.png" alt="Submit" width="48" height="48" ng-
hide="pdt.quantity<1?true:false" ng-click="addToCart(pdt);"/>
</div>
</div>
</body>
</html>
Index.js
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
var imgPath = "img/";
$scope.quantity=0;
$scope.products = [
{
name : "Happy Cycle",
discount:"20%",
price: "2500",
brand : "Wheels",
addedToCart:false,
image : imgPath + "cycle.jpg",
quantity:0
},
{
name : "Kids Shoes",
discount:"10%",
price: "1460",
brand : "Feel Good",
addedToCart:false,
image : imgPath + "shoes.jpg",
quantity:0
},
{
name : "Polo Baby Care Dress",
discount:"20%",
price: "2500",
brand : "Super Hero",
addedToCart:false,
image : imgPath + "shirt.jpg",
quantity:0
},
]
//Add your code here for addToCart function which returns success message
$scope.addToCart = function () {
alert('Product Added to Cart successfully')
return "success";
}
});
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular-
route.min.js"></script>
<script src="index.js"></script>
</head>
</div>
<br />
<div class="search_drop_down">
<!--
Create drop down for brand
bind the value to 'searchKeyword'
Initialize the id as "brandSelection"
-->
<select class="select select-styled" id = "brandSelection" ng-model="searchKeyword" >
<option value="">-- Brand --</option>
<option ng-repeat="pdt in products" >{{pdt.brand}}</option>
</select>
<!--
Create drop down for price
Bind the value to 'selectedPriceFilter'
Call the function 'selectPriceFilter()' on select change
-->
<select class="select select-styled" ng-model="selectedPriceFilter" ng-
options="option for option in options" ng-change="selectPriceFilter(priceFilter)">
<option value="">-- Price --</option>
</select>
<!--
Create a input field for Search
Bind the input value to 'searchKeyword'
Initialize id and class as "search"
-->
<input id="search" placeholder="Search" size="40" type="text" ng-model="searchKeyword ">
</div>
</div>
<div class="single_2">
<div class="prod_desc">
<span class="pdt_name">{{pdt.name}}</span>
<div class="pdt_details_2_col">
<span class="brand">Brand</span>
<span class="brand_name brdName">{{pdt.brand}}</span>
</div>
<div class="pdt_details_2_col">
<span class="brand">Price</span>
<span class="brand_name prdPrice">{{pdt.price}}</span>
</div>
</div>
</div>
<div class="single_3">
<div class="quantity_sec">
<label>Quantity</label>
<br>
<input placeholder="Quantity" type="number" ng-model="pdt.quantity">
</div>
</div>
<div class="single_4">
<input type="image" src="img/greyCart.png" alt="Submit" width="48" height="48"
ng-show="pdt.quantity<1?true:false" />
<input type="image" src="img/orangeCart.png" alt="Submit" width="48" height="48"
ng-hide="pdt.quantity<1?true:false" ng-click="addToCart();" />
</div>
</div>
<!--Product List End-->
</body>
</html>
Index.js
var app = angular.module('myApp', []);
app.controller('myCtrl', function ($scope) {
var imgPath = "img/";
$scope.priceFilter = '';
$scope.selectPriceFilter = "";
$scope.dtsinCart = 0;
$scope.products = [
{
name: "Happy Cycle",
discount: "20%",
price: 2500,
brand: "Wheels",
addedToCart: false,
image: imgPath + "cycle.jpg",
quantity: 0
},
{
name: "Polo Baby Care Dress",
discount: "20%",
price: 500,
brand: "Super Hero",
addedToCart: false,
image: imgPath + "shirt.jpg",
quantity: 0 },
{
name: "Kids Shoes",
discount: "10%",
price: 1000,
brand: "Feel Good",
addedToCart: false,
image: imgPath + "shoes.jpg",
quantity: 0
}
];
$scope.addToCart = function () {
alert('Product Added to Cart successfully')
return "success";
}
//create scope variable options that has 'Low Price to High' and 'High Price to Low' values.
$scope.options = ['Low Price to High', 'High Price to Low'];
//add selectPriceFilter function that assign scope priceFilter to true / false based on condition
$scope.selectPriceFilter = function (priceFilter) {
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular-
route.min.js"></script>
<script src="index.js"></script>
</head>
</div>
<br />
<div class="search_drop_down">
<select id="month" class="select select-styled">
<option value="hide">-- Brand --</option>
<option ng-repeat="pdtBrand in products">{{pdtBrand.brand}}</option>
</select>
</div>
</div>
<div class="single_2">
<div class="prod_desc">
<span class="pdt_name">{{pdt.name}}</span>
<div class="pdt_details_2_col">
<span class="brand">Brand</span>
<span class="brand_name">{{pdt.brand}}</span>
</div>
<div class="pdt_details_2_col">
<span class="brand">Price</span>
<span class="brand_name">{{pdt.price}}</span>
</div>
</div>
</div>
<div class="single_3">
<div class="quantity_sec">
<label>Quantity</label>
<br>
<input placeholder="Quantity" type="number" ng-model="pdt.quantity">
</div>
</div>
<div class="single_4">
<input type="image" src="img/greyCart.png" alt="Submit" width="48" height="48"
ng-show="pdt.quantity<1?true:false" />
<input type="image" src="img/orangeCart.png" alt="Submit" width="48" height="48"
ng-hide="pdt.quantity<1?true:false" ng-click="addToCart();" />
</div>
</div>
</body>
</html>
Index.js
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.quantity=0;
//Add image property to the products and the image should have the url of images
var imagePath1 = "img/cycle.jpg";
var imagePath2 = "img/shoes.jpg";
var imagePath3 = "img/shirt.jpg";
$scope.products = [
{
name : "Happy Cycle",
discount:"20%",
price: "2500",
brand : "Wheels",
addedToCart:false,
image:imagePath1,
quantity:0
},
{
name : "Kids Shoes",
discount:"10%",
price: "1460",
brand : "Feel Good",
addedToCart:false,
image: imagePath2,
quantity:0
},
{
name : "Polo Baby Care Dress",
discount:"20%",
price: "2500",
brand : "Super Hero",
addedToCart:false,
image: imagePath3,
quantity:0
},
]
$scope.addToCart=function(){
alert('Product Added to Cart successfully')
return "success";
}
});
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular-
route.min.js"></script>
<script src="index.js"></script>
</head>
</div>
<br />
<div class="search_drop_down">
<div class="tab">
<button id="newCustomer" class="tablinks active" onclick="openUser(event, 'New_Customer'
)">New Customer
</button>
<button id="existingCustomer" class="tablinks" onclick="openUser(event, 'Existing_Custom
er')">Existing
Customer</button>
</div>
<br>
<label>Must be of 8 characters</label>
<br>
<br>
<!--
Get EmailID input and type should be email
Bind the input to 'emailid'
-->
<br>
<label>Enter Valid Email</label>
<br>
<br>
<!--
Get Password input
Bind the input to 'pswd'
-->
<br>
<label>Must be a combination of uppercase, lowercase and special characters</label>
<br>
<br>
<!--
Create a button which should contain label text as 'Create an Account'
Initialize button 'id' as "reg_new_user" and for class as "create_an_account"
If the inputs are invalid disable the button
When click is made the button should call 'registerUser()'
-->
</form>
</div>
<br>
<label>Enter you Password</label>
<br>
</div>
<script>
function openUser(event, userType) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(userType).style.display = "block";
event.currentTarget.className += " active";
}
</script>
</body>
</html>
Index.js
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
var imgPath = "img/";
$scope.dtsinCart=0;
$scope.products = [
{
name : "Happy Cycle",
discount:"20%",
price: "2500",
brand : "Wheels",
addedToCart:false,
image : imgPath + "cycle.jpg",
quantity:0
},
{
name : "Kids Shoes",
discount:"10%",
price: "1460",
brand : "Feel Good",
addedToCart:false,
image : imgPath + "shoes.jpg",
quantity:0
},
{
name : "Polo Baby Care Dress",
discount:"20%",
price: "2500",
brand : "Super Hero",
addedToCart:false,
image : imgPath + "shirt.jpg",
quantity:0
},
];
$scope.addToCart=function(){
alert('Product Added to Cart successfully')
return "success";
}
//add your code for registerUser which alert user and return successful message
$scope.registerUser = function() {
alert('Registration Successful');
return "successful";
}
});
$http({
method: "GET",
url: "https://jsonplaceholder.typicode.com/users"
}).then(
function successCallback(response) {
$scope.users = response.data;
},
function errorCallback(response) {
alert("Error. Try Again!");
}
);
});