├── Assignment 1 ├── index.html └── index.js ├── Assignment 2 ├── index.html └── index.js └── README.md /Assignment 1/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | JavaScript Assignment # 03 8 | 9 | 10 |

Abdul Haseeb Imran

11 |

JavaScript Assignment

12 | 13 | 14 | -------------------------------------------------------------------------------- /Assignment 1/index.js: -------------------------------------------------------------------------------- 1 | // Declare a variable called “age” and assign it a value of 25. Convert the value of age to a string data type and store it in a new variable called “ageAsString”. 2 | 3 | // Question # 01 4 | 5 | // Answer 6 | let age = 25; 7 | 8 | let ageAsString = String(age); 9 | 10 | console.log("Your age is : ", age); 11 | 12 | console.log("The type of age is : ", typeof age); 13 | 14 | console.log("The type of age As String is : ", typeof ageAsString); 15 | 16 | // Create a program that prompts the user to enter a number and then checks whether that number is even or odd. Display the result to the user using an alert box. 17 | 18 | // Question # 02 19 | 20 | // Answer 21 | let number = prompt("Enter Number : "); 22 | 23 | if (number % 2 == 0) { 24 | alert(number + "This is even Number"); 25 | } else { 26 | alert(number + "This is odd Number"); 27 | } 28 | 29 | // Declare a variable called “temperature” and assign it a value of 72. Convert the temperature to Celsius and store the result in a new variable called “celsius”. Display the value of celsius to the console. 30 | 31 | // Question # 03 32 | 33 | // Answer 34 | let temperature = 72; 35 | 36 | let celsius = ((temperature - 32) * 5) / 9; 37 | 38 | console.log("Temperature convert into celsius is : " + celsius); 39 | 40 | // console.log("The type of the celsius is : " , typeof(celsius)); 41 | 42 | // Create a program that asks the user to enter their name and age. If the user’s age is greater than or equal to 18, display a message to the console that says “Welcome [name], you are an adult”. If the user’s age is less than 18, display a message that says “Sorry [name], you are not yet an adult”. 43 | 44 | // Question # 04 45 | 46 | // Answer 47 | let name = prompt("Enter your name : "); 48 | 49 | let age_ = prompt("Enter your age : "); 50 | 51 | if (age_ >= 18) { 52 | console.log("Welcome " + name + ", you are an adult :) "); 53 | } else { 54 | console.log("Sorry " + name + ", you are not yet an adult"); 55 | } 56 | 57 | // Declare a variable called “isRaining” and assign it a value of true. Using an if...else statement, display a message to the console that says “Bring an umbrella” if it is raining, and “Leave the umbrella at home” if it is not raining. 58 | 59 | // Question # 05 60 | 61 | // Answer 62 | let isRaining = true; 63 | 64 | let isRaining_ = prompt("It is Raining ? Enter please 'Yes' or 'No' "); 65 | 66 | 67 | if (isRaining_ == 'Yes') { 68 | console.log("Bring an umbrella"); 69 | } else if (isRaining_ == 'No') { 70 | console.log("Leave the umbrella at home"); 71 | } else { 72 | console.log("Please Enter Yes or No ?"); 73 | } 74 | -------------------------------------------------------------------------------- /Assignment 2/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Bano Qabil Js Assignment 2 9 | 10 | 11 | 12 |

Js Assignment 2

13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Assignment 2/index.js: -------------------------------------------------------------------------------- 1 | // Assignment 2 2 | 3 | // Write a function that takes an array of numbers as input and returns the sum of all even numbers in the array. 4 | 5 | function takesArray(arr) { 6 | let sum = 0 7 | for (let i = 0; i < arr.length; i++) { 8 | if (arr[i] % 2 === 0) { 9 | sum = sum + arr[i]; 10 | } 11 | } 12 | return sum 13 | } 14 | const arr = [2, 9, 4, 5, 43, 3]; 15 | const result = takesArray(arr); 16 | console.log(result); 17 | 18 | // Write a function that takes a string as input and returns the number of vowels in the string. 19 | 20 | function countVowels(str) { 21 | const vowel = ['a', 'e', 'i', 'o', 'u']; 22 | let count = 0; 23 | for (let i = 0; i < str.length; i++) { 24 | for (let j = 0; j < vowel.length; j++) { 25 | if (str[i] == vowel[j]) { 26 | count++; 27 | break; 28 | } 29 | } 30 | } 31 | return count; 32 | } 33 | 34 | console.log("Vowels are " + countVowels("Hello World!")); 35 | 36 | // Write a function that takes an array of strings as input and returns the length of the longest string in the array. 37 | 38 | function findStringLength(string) { 39 | let stringLength = string[0].length; 40 | 41 | for (let i = 1; i < string.length; i++) { 42 | if (string[i].length > stringLength) { 43 | stringLength = string[i].length; 44 | } 45 | } 46 | console.log("Max string length is " + stringLength); 47 | } 48 | 49 | let strings = ["Hello", "Welcome", "Haseeb"]; 50 | 51 | findStringLength(strings); 52 | 53 | // Write a function that takes an array of numbers as input and returns the average of all the numbers in the array. 54 | 55 | function average(num) { 56 | let sum = 0; 57 | for (let i = 0; i < num.length; i++) { 58 | sum = sum + num[i]; 59 | } 60 | return sum / num.length; 61 | } 62 | 63 | let average2 = average([1, 2, 3, 4, 5]); 64 | console.log(average2); 65 | 66 | // Write a function that takes an object as input and returns an array of all the keys in the object. 67 | 68 | function findKeys() { 69 | let person = { 70 | name: "Abdul Haseeb Imran", 71 | age: 20, 72 | id: 109, 73 | country: "Pakistan", 74 | }; 75 | 76 | return Object.keys(person); 77 | } 78 | 79 | console.log(findKeys()); 80 | 81 | // Write a function that takes an array of objects as input and returns an array of all the values for a specified key in each object. 82 | 83 | function objectKeyValues(person) { 84 | let names = []; 85 | 86 | for (let i = 0; i < person.length; i++) { 87 | names.push(person[i].name); 88 | } 89 | 90 | return names; 91 | } 92 | 93 | let person = [ 94 | { name: "Abdul Haseeb", age: 20 }, 95 | { name: "Ammar", age: 20 }, 96 | { name: "Bilal", age: 20 }, 97 | ]; 98 | 99 | const result1 = objectKeyValues(person); 100 | console.log(result1); 101 | 102 | // Write a function that takes an array of strings as input and returns an array of all the unique strings in the array. 103 | 104 | function getUniqueStrings(array) { 105 | let uniqueStrings = []; 106 | for (let i = 0; i < array.length; i++) { 107 | if (uniqueStrings.indexOf(array[i]) === -1) { 108 | uniqueStrings.push(array[i]); 109 | } 110 | } 111 | return uniqueStrings; 112 | } 113 | 114 | let fruits = ["apple", "orange", "banana", "orange", "pear", "apple"]; 115 | let uniqueFruit = getUniqueStrings(fruits); 116 | console.log(uniqueFruit); 117 | 118 | // Write a function that takes an array of numbers as input and returns the product of all the numbers in the array. 119 | 120 | function getProduct(array) { 121 | let product = 1; 122 | for (let i = 0; i < array.length; i++) { 123 | product = product * array[i]; 124 | } 125 | return product; 126 | } 127 | 128 | let number = [2, 4, 5, 6]; 129 | let product = getProduct(number); 130 | console.log(product); 131 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bano_JavaScript_Assignment_-01 2 | Bano Qabil's MERN Stack JavaScript Assignment focusing on foundational JavaScript skills. 3 | --------------------------------------------------------------------------------