{"id":21553307,"url":"https://github.com/alizayayesha/javascript-assignment-1","last_synced_at":"2025-06-20T09:07:06.502Z","repository":{"id":228702002,"uuid":"774335184","full_name":"AlizayAyesha/JavaScript-assignment-1","owner":"AlizayAyesha","description":"to practice short tasks of js ","archived":false,"fork":false,"pushed_at":"2024-03-28T01:21:37.000Z","size":16,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-18T02:39:45.641Z","etag":null,"topics":["javascript","practice-programming","practice-project"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlizayAyesha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-19T11:20:49.000Z","updated_at":"2024-06-01T20:26:33.000Z","dependencies_parsed_at":"2024-11-24T08:00:55.301Z","dependency_job_id":null,"html_url":"https://github.com/AlizayAyesha/JavaScript-assignment-1","commit_stats":null,"previous_names":["alizayayesha/javascript-programming-assignment-2","alizayayesha/javascript-assignment-1"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AlizayAyesha/JavaScript-assignment-1","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlizayAyesha%2FJavaScript-assignment-1","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlizayAyesha%2FJavaScript-assignment-1/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlizayAyesha%2FJavaScript-assignment-1/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlizayAyesha%2FJavaScript-assignment-1/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlizayAyesha","download_url":"https://codeload.github.com/AlizayAyesha/JavaScript-assignment-1/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlizayAyesha%2FJavaScript-assignment-1/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260915901,"owners_count":23082040,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","practice-programming","practice-project"],"created_at":"2024-11-24T07:10:11.033Z","updated_at":"2025-06-20T09:07:01.490Z","avatar_url":"https://github.com/AlizayAyesha.png","language":"JavaScript","readme":"# JavaScript-Programming-Assignment-2\n\n**Note: Check Rules end of document**\n\n**1. Write a program to take “city” name as input from user. If user enters\n“Karachi”, welcome the user like this: “Welcome to city of lights”**\n\n**index.js**\n\nvar name = prompt(\"please enter your city name\");\nif(\"karachi\".toLocaleUpperCase);\nalert(\"Welcome To The City Of Lights\");\n\n![image](https://github.com/AlizayAyesha/JavaScript-Programming-Assignment-2/assets/68489612/a285844a-98ee-4a1a-91de-dc3fad18dbbe)\n\n![image](https://github.com/AlizayAyesha/JavaScript-Programming-Assignment-2/assets/68489612/cfa80d70-2534-4c34-bb2e-ed0cf580ce89)\n\n-----------------------------------------------------------------------------------\n\n**2. Write a program to take input color of road traffic signal from the user\n\u0026 show the message according to this table:**\n![image](https://github.com/AlizayAyesha/JavaScript-Programming-Assignment-2/assets/68489612/82d2856d-2415-4a2a-9a7d-15e1f2a110a1)\n\n**index.js**\nvar color = prompt(\"Enter a color of traffic signal\");\nif (color.toUpperCase() == \"red\".toUpperCase())\n{\n    alert(\"message is :\" + \"stop your vehicals\")\n}\nelse if (color.toUpperCase() == \"yellow\".toUpperCase()) \n{ alert(\"message is :\"+\" get ready to move your vehicles.\") } \nelse if (color.toUpperCase() == \"green\".toUpperCase())\n { alert(\"message is :\"+\" now you can move your vehicles .\") }\n\n ![image](https://github.com/AlizayAyesha/JavaScript-Programming-Assignment-2/assets/68489612/bdf4da16-6afc-4b25-bccc-56f703db4b93)\n![image](https://github.com/AlizayAyesha/JavaScript-Programming-Assignment-2/assets/68489612/8d61eb56-be8b-4dba-90d4-135751eb7829)\n\n-----------------------------------------------------------------------------------\n\n**3. Run this script, \u0026 check whether alert message would be displayed or\nnot. Record the outputs.**\n\na. var a = 4;\nif (++a === 5) {\nalert(\"given condition for variable a is true\");\n}\n**output**\ngiven condition for variable b is true\n![image](https://github.com/AlizayAyesha/JavaScript-Programming-Assignment-2/assets/68489612/94717e16-2ccb-4fe1-90da-44d2f5459342)\n\n\nb. var b = 82;\nif (b++ === 83){\nalert(\"given condition for variable b is true\");\n}\n**output**\ngiven condition for variable b is true\n![image](https://github.com/AlizayAyesha/JavaScript-Programming-Assignment-2/assets/68489612/6753d908-64f7-438b-bcc5-df14c42abf8b)\n\n\nc. var c = 12;\nif (c++ === 13){\nalert(\"condition 1 is true\");\n}\nif (c === 13){\nalert(\"condition 2 is true\");\n}\nif (++c \u003c 14){\nalert(\"condition 3 is true\");\n}\nif(c === 14){\nalert(\"condition 4 is true\");\n}\n**output**\ncondition 2 is true\n![image](https://github.com/AlizayAyesha/JavaScript-Programming-Assignment-2/assets/68489612/97bbfc9d-b250-4b17-9357-d43abea39e8f)\n\ncondition 4 is true\n\n![image](https://github.com/AlizayAyesha/JavaScript-Programming-Assignment-2/assets/68489612/28dae160-c3d4-45b2-920e-d29f45ff08b9)\n\n\nd. var materialCost = 20000;\nvar laborCost = 2000;\nvar totalCost = materialCost + laborCost;\nif (totalCost === laborCost + materialCost){\nalert(\"The cost equals\");\n}\n**output**\nThe cost equals\n![image](https://github.com/AlizayAyesha/JavaScript-Programming-Assignment-2/assets/68489612/a191bd39-63b4-4733-bf3c-8bf8e4a0bbbc)\n\ne. if (true){\n\nalert(\"True\");\n}\nif (false){\nalert(\"False\");\n}\n**output**\ntrue\n![image](https://github.com/AlizayAyesha/JavaScript-Programming-Assignment-2/assets/68489612/0d272a69-07fc-453d-b410-0896d40c2174)\n\n\nf. if(\"car\" \u003c \"cat\"){\n\nalert(\"car is smaller than cat\");\n}\n\n**output**\ncar is smaller than cat\n![image](https://github.com/AlizayAyesha/JavaScript-Programming-Assignment-2/assets/68489612/666c646b-e84b-44d3-84a7-5b477ecb4074)\n\n\n\n-----------------------------------------------------------------------------------\n\n**4. Write a program to take input the marks obtained in three subjects \u0026\ntotal marks. Compute \u0026 show the resulting percentage on your page.\nTake percentage \u0026 compute grade as per following table:**\n![image](https://github.com/AlizayAyesha/JavaScript-Programming-Assignment-2/assets/68489612/330dfc56-b762-41f3-9280-041d108d3bf4)\n\n**Show the total marks, marks obtained, percentage, grade \u0026 remarks\nlike:**\n\n**index.html**\n\u003chtml\u003e\n    \u003chead\u003e\n        \u003cbody\u003e\n            \u003ctitle\u003eJs sample\u003c/title\u003e \u003cscript src=\" index.js\"\u003e\u003c/script\u003e\n            \u003ch\u003e\n\u003cb\u003e Mark Sheet\u003c/b\u003e\n            \u003c/h\u003e \u003cbr\u003e\n            total marks 268 \u003cbr\u003e\naverage= 89.33333333333333\u003cbr\u003e\n Grade A Excellent\n        \u003c/body\u003e\n    \u003c/head\u003e\n\u003c/html\u003e\n\n**index.js**\nlet m1,m2,m3,sum,percentage\nm1=80\nm2=90\nm3=98\nsum=m1+m2+m3\nconsole.log(\"total marks\" ,sum)\npercentage=sum/3\nconsole.log('average=',percentage);\n\nif (percentage \u003e 80 ) {\n    console.log(\"Grade A\" , \"Excellent\");\n\n}\n\nelse if (percentage \u003e 70) {\n    console.log(\"Grade B\" , \"Good\");\n}\n\nelse if (percentage \u003e 60 ) {\n    console.log(\"Grade B\" , \"You need to improve\");\n}\n\nelse\nconsole.log(\"Fail\" , \"Sorry\");\n![image](https://github.com/AlizayAyesha/JavaScript-Programming-Assignment-2/assets/68489612/b800477c-ee44-4074-8b78-88c6bb06bb8b)\n\n![image](https://github.com/AlizayAyesha/JavaScript-Programming-Assignment-2/assets/68489612/2878ba66-5615-497b-9980-0a5f7cbb193d)\n\n-----------------------------------------------------------------------------------\n\n**5. Guess game:\nStore a secret number (ranging from 1 to 10) in a variable. Prompt\nuser to guess the secret number.\na. If user guesses the same number, show “Bingo! Correct\nanswer”.\nb. If the guessed number +1 is the secret number, show “Close\nenough to the correct answer”.**\n\nvar secretNumber = Math.floor(Math.random() * 10) + 1;\n\nvar guess = (prompt(\"Guess the secret number (between 1 and 10):\"));\n\nif (guess === secretNumber) {\n    alert(\"Bingo! Correct answer\");\n} else if (guess + 1 === secretNumber || guess - 1 === secretNumber) {\n    alert(\"Close enough to the correct answer\");\n} else {\n    alert(\"Sorry, wrong guess. The correct answer was \" + secretNumber);\n}\n\n-----------------------------------------------------------------------------------\n\n**6. Write a program that checks whether the given input is an even\nnumber or an odd number.**\n\nvar input = prompt(\"Enter a number:\");\n\nvar number = +input;\n\nif (!isNaN(number)) {\n    \n    if (number % 2 === 0) {\n        alert(number + \" is an even number.\");\n    } else {\n        alert(number + \" is an odd number.\");\n    }\n} else {\n    alert(\"Invalid input. Please enter a valid number.\");\n}\n\n-----------------------------------------------------------------------------------\n\n**7. Write a program to create a calculator for +,-,*, / \u0026 % using if\nstatements. Take the following input:**\na. First number\nb. Second number\nc. Operation (+, -, *, /, %)\n**Compute \u0026 show the calculated result to user.**\n\nvar firstNumber = parseFloat(prompt(\"Enter the first number:\"));\nvar secondNumber = parseFloat(prompt(\"Enter the second number:\"));\nvar operation = prompt(\"Enter the operation (+, -, *, /, %):\");\n\n\nvar result;\n\n\nif (!isNaN(firstNumber) \u0026\u0026 !isNaN(secondNumber)) {\n\n    switch (operation) {\n        case \"+\":\n            result = firstNumber + secondNumber; break;\n        case \"-\":\n            result = firstNumber - secondNumber; break;\n        case \"*\":\n            result = firstNumber * secondNumber; break;\n        case \"/\":\n            result = secondNumber !== 0 ? firstNumber / secondNumber : \"Error: Division by zero\"; break;\n        case \"%\":\n            result = secondNumber !== 0 ? firstNumber % secondNumber : \"Error: Modulus by zero\"; break;\n        default:\n            result = \"Error: Invalid operation\"; break;\n    }\n    alert(result);\n} else {\n    alert(\"Invalid input. Please enter valid numbers.\");\n}\n\n-----------------------------------------------------------------------------------\n\n**8. Write a program that takes input a number from user \u0026 state whether\nthe number is positive, negative or zero.**\n\n\nvar number = prompt(\"Enter a number:\");\nnumber = +number;\nif (number \u003e 0) {\n    alert(\"The number is positive.\");\n} else if (number \u003c 0) {\n    alert(\"The number is negative.\");\n} else if (number === 0) {\n    alert(\"The number is zero.\");\n} else {\n    alert(\"Invalid input. Please enter a valid number.\");\n}\n\n\n-----------------------------------------------------------------------------------\n\n**9. Write a program that takes a character (i.e. string of length 1) and\nreturns true if it is a vowel, false otherwise**\n\nvar character = prompt(\"Enter a character (a single letter):\");\n\ncharacter = character.toLowerCase();\n\nvar isVowel = false;\nif (character.length === 1) {\n    isVowel = ['a', 'e', 'i', 'o', 'u'].includes(character);\n}\n\nif (isVowel) {\n    alert(\"'\" + character + \"' is a vowel.\");\n} else {\n    alert(\"'\" + character + \"' is not a vowel.\");\n}\n\n-----------------------------------------------------------------------------------\n\n**10. Write a program that**\na. Store correct password in a JS variable.\nb. Asks the user to enter his/her password\nc. Validate the two passwords:\ni. Check if user has entered password. If not, then give the\nmessage “ Please enter your password”\nii. Check if both passwords are the same. If they are the\nsame, show message “Correct! The password you\nentered matches the original password”. Show “Incorrect\npassword” otherwise.\n\nvar correct_Password = \"password123\";\n\nvar entered_Password = prompt(\"Enter your password:\");\n\nif(!entered_Password){\n    alert(\"Please enter your password.\");\n}\nelse if (entered_Password == correct_Password){\n    alert(\"Correct! The password you entered matches the original password.\");\n\n} else{\n    alert(\"Incorrect password.\");\n}\n\n\n-----------------------------------------------------------------------------------\n\n**11. Write a program that take time as input from user in 24 hours clock\nformat like: 1900 = 7pm. Implement the following case using if, else \u0026\nelse if statements**\n\n\nvar time24 = parseInt(prompt(\"Enter time in 24-hour clock format (e.g., 1900):\"));\n\n\nvar hour12, period;\n\nif (time24 \u003e= 0 \u0026\u0026 time24 \u003c= 2400) {\n    if (time24 === 0) {\n        hour12 = 12;\n        period = 'AM';\n    } else if (time24 \u003c 1200) {\n        hour12 = Math.floor(time24 / 100);\n        period = 'AM';\n    } else if (time24 === 1200) {\n        hour12 = 12;\n        period = 'PM';\n    } else {\n        hour12 = Math.floor((time24 - 1200) / 100);\n        period = 'PM';\n    }\n\n    alert(\"Time in 12-hour clock format: \" + hour12 + (time24 % 100 === 0 ? '' : ':' + (time24 % 100)) + ' ' + period);\n} else {\n    alert(\"Invalid input. Please enter time in the range 0000 to 2400.\");\n}\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falizayayesha%2Fjavascript-assignment-1","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falizayayesha%2Fjavascript-assignment-1","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falizayayesha%2Fjavascript-assignment-1/lists"}