└── js ass2 ├── index.html └── app.js /js ass2/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /js ass2/app.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | // CHAPTER 21-42 4 | // TASK NO 1: 5 | // var firstName = prompt("Enter First Name:"); 6 | // var lastName = prompt("Enter Last Name"); 7 | // document.write("Hello "+firstName+" "+lastName); 8 | 9 | // TASK NO 2: 10 | // var input = prompt("Enter your favorite phone brand:"); 11 | // document.write("My favorite phone is: "+input); 12 | // document.write("
"); 13 | // document.write("Length of string: "+input.length); 14 | 15 | // TASK NO 3: 16 | // var word = "Pakistani"; 17 | // document.write("String: "+word+"
"); 18 | // word = word.toLowerCase(); 19 | // document.write("Index of 'n': "+word.indexOf("n")); 20 | 21 | // TASK NO 4: 22 | // var word = "Hello World"; 23 | // word = word.toLowerCase(); 24 | // document.write("Last Index of 'l': "+word.lastIndexOf("l")); 25 | 26 | // TASK NO 5: 27 | // var word = "Pakistani"; 28 | // document.write("String: "+word+"
"); 29 | // document.write("Character at index 3: "+word[3]); 30 | 31 | // TASK NO 6: 32 | // var firstName = prompt("Enter First Name:"); 33 | // var lastName = prompt("Enter Last Name"); 34 | // document.write("Hello "+firstName.concat(" "+lastName)); 35 | 36 | // TASK NO 7: 37 | // var word = "Hyderabad"; 38 | // var result = word.replace("Hyder","Islam"); 39 | // document.write("Before: "+word+"
"); 40 | // document.write("After: "+result); 41 | 42 | // TASK NO 8: 43 | // var message = "Ali and Sami are best friends. They play cricket and football together"; 44 | // var result = message.replace(/and/g,"&"); 45 | // document.write("Before: "+message+"
"); 46 | // document.write("After: "+result); 47 | 48 | // TASK NO 9: 49 | // var value = "472" 50 | // document.write("Value: "+value+"
"+"Type: "+typeof(value)); 51 | // value = parseInt(value); 52 | // document.write("
Value: "+value+"
"+"Type: "+typeof(value)); 53 | 54 | // TASK NO 10: 55 | // var userInput = prompt("Type anything: "); 56 | // document.write("Before: "+userInput+"
"); 57 | // userInput = userInput.toUpperCase(); 58 | // document.write("After: "+userInput); 59 | 60 | // TASK NO 11: 61 | // var userInput = prompt("Type anything: "); 62 | // document.write("Before: "+userInput+"
"); 63 | // var firstChar = userInput.slice(0,1); 64 | // var otherChar = userInput.slice(1); 65 | // firstChar = firstChar.toUpperCase(); 66 | // otherChar = otherChar.toLowerCase(); 67 | // userInput = firstChar+otherChar; 68 | // document.write("After: "+userInput); 69 | 70 | // TASK NO 12: 71 | // var num = 35.36; 72 | // document.write("Value: "+num+"
"+"Type: "+typeof(num)); 73 | // num = num.toString(); 74 | // num = num.split('.').join(""); 75 | // document.write(num); 76 | // document.write("
Value: "+num+"
"+"Type: "+typeof(num)); 77 | 78 | // TASK NO 13: 79 | // var username = prompt("Enter Username: "); 80 | // if(username.match(/[\@\.\,\!]/)===null){ 81 | // alert(username); 82 | // } 83 | // else{ 84 | // alert("Please Enter a valid username."); 85 | // } 86 | 87 | // TASK NO 14: 88 | // var A = ["cake", "apple pie", "cookie", "chips", "patties"] 89 | // var userInput = prompt("Welcome to ABC Bakery. What do you want to order Sir/Ma'am"); 90 | // userInput = userInput.toLowerCase(); 91 | // for(var i = 0; inot available in our Bakery"); 99 | // break; 100 | // } 101 | // } 102 | 103 | // TASK NO 16: 104 | // var university = "University of Karachi"; 105 | // document.write("Before: "+university) 106 | // var arr = university.split("") 107 | // document.write("
After: "+arr+"
"); 108 | // for(var i=0; i") 110 | // } 111 | 112 | // TASK NO 17: 113 | // var userInput = prompt("Enter anything: "); 114 | // document.write(userInput.charAt(userInput.length-1)); 115 | 116 | // TASK NO 18: 117 | // var string = "The quick brown fox jumps over the lazy dog." 118 | // document.write("Text: "+string); 119 | // string = string.toLowerCase(); 120 | // var wordCount = string.match(/the/g).length; 121 | // document.write("
There are "+wordCount+" occurrences of the word 'the'") 122 | 123 | //====================================================== CHAPTER 26-30===================================================== 124 | 125 | // TASK NO 1: 126 | // var userInput = +prompt("Enter a number with decimal:"); 127 | // if(userInput>0){ 128 | // document.write("number: "+userInput); 129 | // document.write("
Round off value:"+Math.round(userInput)) 130 | // document.write("
Floor value:"+Math.floor(userInput)) 131 | // document.write("
Ceil value:"+Math.ceil(userInput)) 132 | // } 133 | // else{ 134 | // alert("Input a positive number!"); 135 | // } 136 | 137 | // TASK NO 2: 138 | // var userInput = +prompt("Enter a negative floating point number:"); 139 | // if(userInput<0){ 140 | // document.write("number: "+userInput); 141 | // document.write("
Round off value:"+Math.round(userInput)) 142 | // document.write("
Floor value:"+Math.floor(userInput)) 143 | // document.write("
Ceil value:"+Math.ceil(userInput)) 144 | // } 145 | // else{ 146 | // alert("Input a negative floating point number!"); 147 | // } 148 | 149 | // TASK NO 3: 150 | // var userInput = +prompt("Enter a number:"); 151 | // document.write("Absolute value of "+userInput+ " is "+Math.abs(userInput)); 152 | 153 | // TASK NO 4: 154 | // var dice = Math.random(); 155 | // dice = (dice * 6) + 1; 156 | // dice = Math.floor(dice); 157 | // document.write("random dice value: "+dice); 158 | 159 | // TASK NO 5: 160 | // var coin = Math.random(); 161 | // coin = (coin * 2) + 1; 162 | // coin = Math.floor(coin); 163 | // document.write(coin); 164 | // if(coin==1){ 165 | // document.write("
Random Coin Value: Heads"); 166 | // } 167 | // else{ 168 | // document.write("
Random Coin Value: Tails"); 169 | // } 170 | 171 | // TASK NO 6: 172 | // var value = Math.random(); 173 | // value = (value * 100) + 1; 174 | // value = Math.floor(value); 175 | // document.write("Random value: "+value); 176 | 177 | // TASK NO 7: 178 | // var userInput = prompt("Enter your weight is kilograms:"); 179 | // userInput = parseInt(userInput); 180 | // document.write("The weight of user is "+ userInput +" Kilograms"); 181 | 182 | // TASK NO 8: 183 | // var value = Math.random(); 184 | // value = (value * 10) + 1; 185 | // value = Math.floor(value); 186 | // do{ 187 | // userInput = +prompt("Enter a number between 1-10:"); 188 | // }while(userInput>10); 189 | // document.write("Random Value: "+value); 190 | // document.write("
Your Value: "+userInput); 191 | // if(userInput ===value){ 192 | // document.write("
Congratulations You won!"); 193 | // } 194 | // else{ 195 | // document.write("
Better luck next time!"); 196 | // } 197 | 198 | //====================================================== CHAPTER 31-34===================================================== 199 | 200 | // TASK NO 1: 201 | // var time=new Date() 202 | // document.write(time+"
") 203 | 204 | // TASK NO 2: 205 | // var time=new Date() 206 | // var arr=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",] 207 | // var mon=time.getMonth() 208 | // var name=arr[mon] 209 | // document.write("current month is"+" "+name+"
") 210 | 211 | // TASK NO 3: 212 | // var time=new Date() 213 | // var dayNames = ["Sunday", "Monday", "Tueday", "Wednesday", "Thursday", "Friday", "Saturday"]; 214 | // var din=time.getDay() 215 | // var nam=dayNames[din] 216 | // document.write("today is "+" "+ nam[0],nam[1],nam[2] +"
") 217 | 218 | // TASK NO 4: 219 | // var time=new Date() 220 | // var dayNames = ["Sunday", "Monday", "Tueday", "Wednesday", "Thursday", "Friday", "Saturday"]; 221 | // var din=time.getDay() 222 | // var nam=dayNames[din] 223 | // if(nam==="Sunday"||nam==="Saturday"){ 224 | // document.write("its fun day") 225 | // }else{ 226 | // document.write("its week day"+"
") 227 | // } 228 | 229 | // TASK NO 5: 230 | // var time=new Date() 231 | // var date=time.getDate() 232 | // if(date<=15){ 233 | // document.write("its first fifteen days of month") 234 | // }else{ 235 | // document.write("last days of month"+"
") 236 | // } 237 | // TASK NO 6: 238 | // var time=new Date() 239 | // var t=time.getTime() 240 | // document.write(t) 241 | // var currentDate = new Date() 242 | // var pretime =currentDate.getTime() 243 | // var pretimeMinu = pretime/(1000*60*60) 244 | // document.write("
Minutes: "+pretimeMinu) 245 | 246 | 247 | // TASK NO 7: 248 | // var time = new Date() 249 | // var hours = time.getHours() 250 | // if (hours<12){ 251 | // document.write("its AM") 252 | // }else{ 253 | // document.write("its PM") 254 | // } 255 | 256 | 257 | // var lastDate = new Date("Apr 1,2020") 258 | // var lastDatemili = lastDate.getTime() 259 | // var currentDate=new Date() 260 | // var currentDatemili =currentDate.getTime() 261 | // var diff=currentDatemili - lastDatemili 262 | // var days = diff/(1000*60*60*24) 263 | // days=Math.floor(days) 264 | // document.write(days + " "+ "days since 1 RAMZAN") 265 | 266 | 267 | // var newDate = new Date("Dec 31, 2020") 268 | // var newDatemili = newDate.getTime() 269 | // var currentDate = new Date() 270 | // var currentDatemili = currentDate.getTime() 271 | // var diff = newDatemili -currentDatemili 272 | // var seconds =diff/(1000*60*60) 273 | // document.write(seconds) 274 | 275 | // var date = new Date() 276 | // date.toString() 277 | // alert(date) 278 | // date.setFullYear(1925) 279 | 280 | // alert(date) 281 | 282 | //====================================================== CHAPTER 35-38===================================================== 283 | 284 | 285 | // function currentDate(){ 286 | // var date = new Date() 287 | // date.toString() 288 | // alert(date) 289 | // } 290 | // currentDate() 291 | 292 | 293 | // function greet(){ 294 | // var firstname=prompt("enter your first name") 295 | // var lastname=prompt("enter your last name") 296 | // var fullName=firstname +" "+ lastname 297 | // alert("Welcome to this page"+" "+ fullName) 298 | // } 299 | // greet() 300 | 301 | 302 | // function add(){ 303 | // var num1=+prompt("enter no") 304 | // var num2=+prompt("enter no") 305 | // var total = num1 + num2 306 | // return total 307 | // } 308 | 309 | // document.write("total is"+" "+ add()) 310 | 311 | // function calc(num1,num2){ 312 | // var result=num1 -num2 313 | // return result 314 | // } 315 | // document.write(calc(7,2)) 316 | 317 | // function square(a){ 318 | // var result=a*a 319 | // return result 320 | // } 321 | // document.write(square(+prompt("enter no"))) 322 | // function A(a=7,b=5){ 323 | // var result = a*b 324 | // return result 325 | // } 326 | // document.write(A()) 327 | // function A(a,b){ 328 | // var result = a*b 329 | // return result 330 | // } 331 | // document.write(A(5,5)) 332 | 333 | // var arr=prompt("enter any string") 334 | // arr.length 335 | // var arr1=[] 336 | // for(i=arr.length;i>=0;i--){ 337 | // arr1.push(arr[i]) 338 | // } 339 | // var a=arr1.slice(0,arr1.length) 340 | // a=a.toString() 341 | // console.log(a) 342 | 343 | 344 | // function calcCircumferrence(r){ 345 | // var result=2*(22/7)*r 346 | // return result 347 | 348 | // } 349 | // document.write( calcCircumferrence(7)+"
") 350 | // function square(a){ 351 | // var result=a*a 352 | // return result 353 | // } 354 | // function calcArea(){ 355 | // var re9sult1 = 3.142*(square(7)) 356 | // return result1 357 | // } 358 | // document.write(calcArea()) 359 | 360 | 361 | // var msg =prompt("enter any message") 362 | // var str=msg.length 363 | // var con =msg.slice(0,msg.indexOf(" ")) 364 | // console.log(con) 365 | // var firstletter=con.charAt(0) 366 | // firstletter= firstletter.toUpperCase() 367 | // console.log(firstletter + con.slice(1)) 368 | 369 | 370 | // function coounting(){ 371 | // var start=+prompt("enter start no") 372 | // var end=+prompt("enter end no") 373 | // for(i=start;i<=end;i++){ 374 | // document.write(i+"
") 375 | // } 376 | 377 | // } 378 | // document.write(coounting()) 379 | 380 | //====================================================== CHAPTER 39-42===================================================== 381 | 382 | // TASK NO 1: 383 | // var a = 2; 384 | // var b = 2; 385 | // function power(a,b){ 386 | // var result = Math.pow(a,b); 387 | // return result; 388 | // } 389 | // document.write(a+"^"+b +" = "+power(a,b)); 390 | 391 | // TASK NO 2: 392 | // function checkLeapYear(year) { 393 | // if ((0 == year % 4) && (0 != year % 100) || (0 == year % 400)) { 394 | // document.write(year + ' is a leap year'); 395 | // } else { 396 | // document.write(year + ' is not a leap year'); 397 | // } 398 | // } 399 | // var year = +prompt("Enter a year:"); 400 | // checkLeapYear(year); 401 | 402 | // TASK NO 3: 403 | // function findArea( a, b, c) 404 | // { 405 | // if (a < 0 || b < 0 || c < 0 || (a + b <= c) || a + c <= b || b + c <= a) 406 | // { 407 | // document.write( "Not a valid triangle"); 408 | // return; 409 | // } 410 | // let s = (a + b + c) / 2; 411 | // return Math.sqrt(s * (s - a) * (s - b) * (s - c)); 412 | // } 413 | // let a = 3.0; 414 | // let b = 4.0; 415 | // let c = 5.0; 416 | // document.write( "Area is " + findArea(a, b, c)); 417 | 418 | // TASK NO 4: 419 | // var mark1 = +prompt("Enter Mark of Subject 1"); 420 | // var mark2 = +prompt("Enter Mark of Subject 2"); 421 | // var mark3 = +prompt("Enter Mark of Subject 3"); 422 | // function average(mark1,mark2,mark3){ 423 | // var marks = mark1 +mark2 +mark3; 424 | // return marks; 425 | // } 426 | // function percentage(mark1,mark2,mark3){ 427 | // var perc = (average(mark1,mark2,mark3)/300)*100; 428 | // return perc; 429 | // } 430 | // function mainFunction(mark1,mark2,mark3){ 431 | // average(mark1,mark2,mark3); 432 | // document.write("Percentage: "+percentage(mark1,mark2,mark3)); 433 | // } 434 | // mainFunction(mark1,mark2,mark3); 435 | --------------------------------------------------------------------------------