Assignment 6
Assignment 6
Assignment 6
Q1. Write an AJS to input your display the same in uppercase. name in
lower case and display the same in upper case
<!DOCTYPE html>
<html>
<head>
<title>Uppercase/Lowercase Converter</title>
</head>
<body>
<label for="nameInput">Enter your name:</label>
<input type="text" id="nameInput">
<button onclick="convertText()">Convert</button>
<br>
<label for="nameOutput">Name in lowercase:</label>
<span id="nameOutput"></span>
<br>
<label for="uppercaseOutput">Name in uppercase:</label>
<span id="uppercaseOutput"></span>
<script>
function convertText() {
/ Get input value
var nameInput = document.getElementById('nameInput').value;
Q2. write an AJS to display the names of those countries from an array
defined inside a controller that has the letter "i" in it.
Ans:
(Index.html)
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title>Country Names Filter</title>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
</head>
<body ng-controller="MainController">
<div>
<label>Countries with 'i':</label>
<ul>
<li ng-repeat="country in countriesWithI">{{ country }}</li>
</ul>
</div>
<script src="app.js"></script>
</body>
</html>
(App.js)
angular.module('myApp', [])
.controller('MainController', function($scope) {
/ Array of countries
$scope.countries = ["India", "Indonesia", "Ireland", "Italy", "Iran", "Iraq"];
Output:
Q3. write an AJS to display the last 10 elements from an array defined
inside a controller (The array must contain 25 values)
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title>Last 10 Elements Display</title>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
</head>
<body ng-controller="MainController">
<div>
<h2>Last 10 Elements:</h2>
<ul>
<li ng-repeat="element in lastTenElements">{{ element }}</li>
</ul>
</div>
<script src="app.js"></script>
</body>
</html>
angular.module('myApp', [])
.controller('MainController', function($scope) {
/ Array of 25 values
$scope.array = Array.from({ length: 25 }, (_, i) => i + 1);
Output:
Q4. Write an AJS to show how you can filter an array based on user input.
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<title>Array Filtering</title>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
</head>
<body ng-controller="MainController">
<div>
<label>Filter:</label>
<input type="text" ng-model="filterText">
</div>
<div>
<h2>Filtered Results:</h2>
<ul>
<li ng-repeat="item in filteredArray">{{ item }}</li>
</ul>
</div>
<script src="app.js"></script>
</body>
</html>
angular.module('myApp', [])
.controller('MainController', function($scope) {
/ Sample array
$scope.array = ["Apple", "Banana", "Orange", "Grapes", "Watermelon"];