Skip to content

Commit d9abae8

Browse files
author
gsagariw
committed
Added questions and fixed some errors in code
1 parent e5b419f commit d9abae8

12 files changed

Lines changed: 292 additions & 19 deletions

File tree

‎[01] Basics/[21] Page Redirection/index.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<body>
88
<h1 onclick="Redirect()">My Blog</h1>
9+
<a href="google.com" target="_blank">google.com</a>
910
<noscript>JS not supported</noscript>
1011
</body>
1112
</html>

‎[01] Basics/[23] HTML DOM/index.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</head>
1010

1111
<body>
12-
<div id="myDiv"><b>Hello World</b></div>
12+
<div id="myDiv" style="color: red"><b>Hello World</b></div>
1313

1414
<noscript>JS not supported</noscript>
1515
</body>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
**Q1. Determine whether a year is a leap year or not**
2+
3+
Steps:
4+
5+
1. If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.
6+
2. If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.
7+
3. If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.
8+
4. The year is a leap year (it has 366 days).
9+
5. The year is not a leap year (it has 365 days).
10+
11+
12+
**Q2. Find the length of the string (entered by the user) without using the built-in function.**
13+
14+
Following is the example of output:
15+
```
16+
Input string: javascript
17+
Output: Length of string: 10
18+
```
19+
20+
21+
**Q3. check whether a number (entered by the user) is a perfect number or not.**
22+
23+
A perfect number, a positive integer that is equal to the sum of its proper divisors. The smallest perfect number is 6, which is the sum of 1, 2, and 3.
24+
25+
Input: 6
26+
Proper divisors of 6 are: 1, 2 and 3
27+
Sum of proper divisors = (1 + 2 + 3) which is equal to 6 (our input)
28+
Hence, 6 is perfect number
29+
30+
31+
**Q4. check whether the number entered by the user is a strong number or not.**
32+
33+
Strong Numbers are the numbers whose sum of factorial of digits is equal to the original number. Given a number, check if it is a Strong Number or not.
34+
35+
Input: 145
36+
Output: Yes
37+
Sum of digit factorials = 1! + 4! + 5!
38+
= 1 + 24 + 120
39+
= 145
40+
41+
42+
**Q5. check whether the number entered by the user is a happy number or not. The user will enter 20 input number and program will check if it is a happy number or not.**
43+
44+
A happy number is starting with any positive integer, replace the number by the sum of the squares of its digits in base-ten, and repeat the process until the number either equals 1 (where it will stay), or it loops endlessly in a cycle that does not include 1. Those numbers for which this process ends in 1 are happy numbers, while those that do not end in 1 are unhappy numbers (or sad numbers)
45+
46+
If a number is happy, then all members of its sequence are happy; if a number is unhappy, all members of the sequence are unhappy.
47+
48+
Input: n = 19
49+
Output: 19 is Happy Number,
50+
1^2 + 9^2 = 82
51+
8^2 + 2^2 = 68
52+
6^2 + 8^2 = 100
53+
1^2 + 0^2 + 0^2 = 1
54+
As we reached to 1, 19 is a Happy Number.
55+
56+
57+
**Q6. count all vowels in a sentence (entered by the user).**
58+
59+
Following example shows the output of the program:
60+
61+
Input: Hello C Programming
62+
Output: 5 (vowels)
63+
64+
**Q7. check whether a number entered by the user is magic number or not. The user will enter 1729 input number and program will calculate and check if it is magic number or not and print on the console.**
65+
66+
What is the magic number?
67+
Input: 1729
68+
Sum of digits of the given number.(1 + 7 + 2 + 9 => 19)
69+
The reverse of 19 is 91
70+
The product of digit sum and the reverse of digit sum.(19 X 91 = 1729)
71+
If the product value and the given input are same,
72+
then the given number is a magic number.(19 X 91 <=> 1729)
73+
74+
Output: So, 1729 is a magic number.
75+
76+

‎[02] Basics II [ES6]/[04] Arrays/custom.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ myArray[3] = "Hello";
5858

5959
// Add and remove element from front or back end of an array
6060
myArray.unshift(3); // Add as the first element
61-
let someVar = myArray.shift(); // Remove first element and return it
61+
let someVar1 = myArray.shift(); // Remove first element and return it
6262

6363
myArray.push(3); // Add as the last element
64-
let someVar = myArray.pop(); // Remove last element and return it
64+
let someVar2 = myArray.pop(); // Remove last element and return it
6565

6666
// Join all elements of an array with semicolon
6767
let myArray0 = [32,false,"js",12,56,90];

‎[04] Advanced JS/[01] Error Handling/script.js‎

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# The HTML DOM
2+
3+
- DOM Stands for **D**ocument **O**bject **M**odel
4+
- The browser creates a DOM of the page when a webpage is first loaded
5+
- It defines the logical structure of documents and the way a document is accessed and manipulated.
6+
- The HTML DOM model is constructed as a tree of **Objects**:
7+
8+
![DOM](dom.gif)
9+
10+
*Image source: https://www.w3schools.com/js/pic_htmltree.gif*
11+
12+
With the help of DOM, JS can be used to create dynamic HTML.
13+
14+
- Javascript can:
15+
- change all the HTML elements, attributes and CSS styles in the page
16+
- remove existing HTML elements and attributes
17+
- add new HTML elements and attributes
18+
- react to all existing HTML events in the page
19+
- create new HTML events in the page
20+
21+
**Bottom line: The HTML DOM is a standard for how to get, change, add, delete or react to events of the HTML elements.**
2.98 KB
Loading
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Document and Window</title>
6+
<script src="script.js"></script>
7+
</head>
8+
<body>
9+
<div class="container">
10+
<div id="inner">
11+
<p id="demo">Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p>
12+
<button id="theButton">Hello</button>
13+
</div>
14+
</div>
15+
<noscript>JS not supported</noscript>
16+
</body>
17+
</html>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"use strict";
2+
3+
console.log(window);
4+
/*
5+
Window is the main JavaScript object root, aka the global object in a browser, also can be treated as the root of the document object model.
6+
You can access it as window in most of the cases (in the browser);
7+
*/
8+
9+
10+
console.log(document);
11+
console.log(window.document);
12+
/*
13+
window.document or just document is the main object of the visible (or better yet: rendered) document object model/DOM.
14+
We can use the document object to manipulate DOM to change look and feel of a webpage
15+
*/
16+
17+
// Some of the document properties
18+
19+
console.log(document.anchors); // All <a> elements that have a name attribute
20+
console.log(document.body); // get the <body> element
21+
console.log(document.title); // get the <title> element
22+
console.log(document.URL); // get complete URL of the document
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>DOM Manipulation</title>
6+
<style>
7+
#button {
8+
width: 250px;
9+
height: 250px;
10+
position: absolute;
11+
background-color: #125eff;
12+
}
13+
</style>
14+
15+
</head>
16+
<body>
17+
<div class="container">
18+
<div id="inner">
19+
<p id="demo" style="border: 1px solid;">Lorem ipsum dolor sit amet, consectetur adipisicing elit. </p>
20+
<input type="text" name="test">
21+
<button class="theButton" onclick="addNewElement()">Hello</button>
22+
</div>
23+
</div>
24+
25+
<div class="container2">
26+
<div id="button" onmouseover="oops(this);">
27+
OK
28+
</div>
29+
</div>
30+
31+
<script>
32+
console.log("document.getElementById('innner')", document.getElementById("inner"));
33+
console.log("document.getElementsByClassName('theButton')", document.getElementsByClassName("theButton"));
34+
console.log("document.getElementsByName('test')", document.getElementsByName("test"));
35+
console.log("document.getElementsByTagName('p')", document.getElementsByTagName("p"));
36+
</script>
37+
<script src="script.js"></script>
38+
<noscript>JS not supported</noscript>
39+
</body>
40+
</html>

0 commit comments

Comments
 (0)