Full Stack Devp
Full Stack Devp
Full Stack Devp
Anthe VS Code ithe install ipoindi! Ippud andulo poy pani cheskundam :)
HTML Introduction
HTML stands for HyperText Markup Language. It is the standard markup language used to
create and structure content on the World Wide Web (WWW). HTML is the backbone of
most web pages and is used to define the structure and layout of web documents, including
text, images, links, forms, and multimedia.
<h1>, <p>, and <button> tags gurinchi ithe chuddam mowa ippudu.
The <h1> tag is used to define the top-level or main heading of a webpage or a section
within a webpage.
It represents the most important and largest heading on the page.
Web browsers typically render text within <h1> tags in a larger and bold font to
emphasize its significance.
It's good practice to use <h1> for the main title of a page, and you can use it
hierarchically with other heading tags like <h2>, <h3> ,<h4> <h5> ,<h6>for
subheadings with decreasing importance.
Example:
Example:
<button> Tag:
Example:
<button>Subscribe Here!</button>
Assignment Question:
Create an HTML webpage using the concepts introduced in this session, specifically
employing the <h1>, <p>, and <button> tags.
o What is CSS?
CSS stands for Cascading Style Sheets.
It is a stylesheet language used for describing the presentation and
formatting of a document written in HTML (Hypertext Markup
Language).
CSS allows you to control the layout, colors, fonts, and other visual
aspects of a web page, making it visually appealing and user-friendly.
o Why Use CSS?
Separation of Concerns: CSS separates the content (HTML) from its
presentation, making it easier to maintain and update web pages.
Consistency: CSS enables you to apply consistent styles across
multiple pages of a website.
Flexibility: You can change the look and feel of a website without
altering its underlying structure (HTML).
CSS Color
/* style.css */
p {
color: blue; /* Using a named color */
}
Background Color
CSS allows for a wide range of styling options beyond just color and background
color, including font size, margin, padding, border, and more. Veeti gurinchi manam
further tutorials lo telskuntam. Stay tuned :)
In CSS, you can use the height and width properties to control the dimensions of
HTML elements. Here's how you can use them:
In this example, any element with the class box will have a height of 100 pixels and a
width of 200 pixels.
This <div> element will have the specified height and width.
Text Alignment
The text-align property in CSS is used to control the horizontal alignment of text
within an element. Here's how it works:
Assignment Question:
Create a CSS rule that styles the header of the page with the following properties:
Hello Mithrooooms! Eeroj manam enni rakalga color ki values ivacho chudham. In
CSS, there are several ways to specify color values. Each method has its own syntax
and use cases. Here are the most common types of color values in CSS:
CSS provides a set of predefined color keywords that represent common colors. These
keywords are easy to use and remember. For example:
color: red;
background-color: blue;
Some common keyword color values include red, blue, green, black, white,
yellow, and many others.
In this example, #FF0000 represents the color red, where FF is the maximum intensity
of red, and 00 indicates no intensity of green and blue.
RGBA color values are similar to RGB, but they include an additional alpha channel,
which represents the opacity of the color. The alpha value is specified as a number
between 0 (fully transparent) and 1 (fully opaque). For example:
HSL (Hue, Saturation, Lightness) color values represent colors by specifying the hue
(color), saturation (vividness), and lightness (brightness) using the hsl() function.
For example:
HSLA color values are similar to HSL, but they include an alpha channel for opacity,
just like RGBA. For example:
These are the primary ways to specify color values in CSS. The choice of which
method to use depends on your specific design requirements and preferences.
Assignment Question:
Build a web page utilizing hexadecimal, RGB, RGBA, HSL, and HSLA color values.
HTML Tags
Watch Tutorial → Click Here
HTML Tags
1. Opening Tag: The opening tag is enclosed in angle brackets (<>) and
indicates the beginning of an HTML element. It typically contains the name of
the element. For example, <p> is the opening tag for a paragraph element.
2. Content: The content is the actual information or text you want to display
within the HTML element. It appears between the opening and closing tags.
3. Closing Tag: The closing tag also uses angle brackets but includes a forward
slash (/) before the element name. It indicates the end of the HTML element.
For example, </p> is the closing tag for a paragraph element.
In this example:
HTML tags are the building blocks of web pages, and by using different tags and
attributes, you can structure text, insert images, create links, define headings, and
much more, allowing you to create rich and interactive web content.
Inka chaala HTML Tags untay mowa! Avasaranni batti mana Google
thalli ni adigi vaadukodame.
Assignment Question:
Create a webpage that incorporates the HTML topics you've learned so far. Highlight
specific HTML tags and create elements that link to my YouTube channel
(https://youtube.com/@niharrdg) and my Instagram page
(https://instagram.com/niihaaarrrr). Use creative design and make the best use of CSS
to enhance the visual appeal of your webpage.
Congrats Mowa Successful ga complete chesnav! Next session lo
kaluddam :)
Hellooooo mowa brooos! Eeroj manam HTML Lists and Tables pakkaki oka look
eseddam :)
HTML Lists
HTML lists are used to present information in a structured and organized manner.
There are three types of lists in HTML: ordered lists, unordered lists, and definition
lists. Each type of list has its own purpose and can be customized using CSS
properties.
0. Ordered Lists (<ol>): Ordered lists are used when the order of the items is
significant. Each list item is preceded by a number or another marker,
typically starting from 1 and incrementing sequentially.
1. <ol>
2. <li>Item 1</li>
3. <li>Item 2</li>
4. <li>Item 3</li>
5. </ol>
6.
type: Specifies the numbering style. Default is "decimal," but you can
use "lower-alpha," "upper-alpha," "lower-roman," "upper-roman," etc.
<ol type="I">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ol>
start: Allows you to start the numbering from a specific value.
<ol start="5">
<li>Item 5</li>
<li>Item 6</li>
<li>Item 7</li>
</ol>
7. Unordered Lists (<ul>): Unordered lists are used when the order of items
doesn't matter. Each list item is typically preceded by a bullet point or another
marker.
8. <ul>
9. <li>Item A</li>
10. <li>Item B</li>
11. <li>Item C</li>
12. </ul>
13.
Common list style properties for unordered lists:
type: Specifies the marker style. Default is "disc," but you can use
"circle," "square," or define custom markers using CSS.
<ul style="list-style-type: square;">
<li>Item X</li>
<li>Item Y</li>
<li>Item Z</li>
</ul>
14. Definition Lists (<dl>) (Idi ekkuva vaadam ankondi practical ga, ina
parle okasari look ithe eseyyandi): Definition lists are used to define terms
and their corresponding definitions. They consist of term (<dt>) and definition
(<dd>) pairs.
15. <dl>
16. <dt>Term 1</dt>
17. <dd>Definition 1</dd>
18. <dt>Term 2</dt>
19. <dd>Definition 2</dd>
20. </dl>
21.
CSS Properties for List Styling: You can further style your lists using CSS. Here are
some common CSS properties for customizing lists:
HTML Tables
HTML tables are used to display data in a structured grid format, with rows and
columns. Tables consist of various components, including the table itself, rows,
headers, and data cells. Here's an explanation of HTML tables with code snippets:
Creating a Basic Table: To create a basic HTML table, you'll use the <table>
element to define the table structure. Within the table, you use <tr> elements to
define rows, <th> elements for table headers (optional), and <td> elements for data
cells.
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Dodagatta Nihar</td>
<td>19</td>
</tr>
</table>
Table Headers (<th>): You can use <th> elements to define table headers. These
headers are typically bold and centered by default. They help describe the content of
the columns.
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Peru teliyani Ammai</td>
<td>19</td>
</tr>
<!-- More rows... -->
</table>
Ee kinda unna examples ni meeru kuda VS Code lo try out chesi chudandi :)
Table Captions (<caption>): You can add a caption to your table using the
<caption> element. The caption is typically placed above the table.
<table>
<caption>Student Information</caption>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Emily</td>
<td>22</td>
</tr>
<!-- More rows... -->
</table>
Table Borders and Styling: You can use CSS to style tables, including adding borders,
changing fonts, and applying background colors. Here's an example of adding a
border to a table:
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ccc;
padding: 8px;
text-align: left;
}
</style>
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Michael</td>
<td>30</td>
</tr>
<!-- More rows... -->
</table>
Spanning Rows and Columns: You can use the rowspan and colspan attributes to
make cells span multiple rows or columns.
<table>
<tr>
<th>Name</th>
<th>Details</th>
</tr>
<tr>
<td rowspan="2">John</td>
<td>Age: 25</td>
</tr>
<tr>
<td>Country: USA</td>
</tr>
<!-- More rows... -->
</table>
HTML tables are versatile and allow you to present data in various formats, from
simple grids to complex data tables. You can further enhance their appearance and
functionality using CSS and JavaScript if needed.
Attempt Quiz → Click Here
Assignment Question:
Design elegant HTML lists and tables, enhancing their visual appeal with CSS
styling.
HTML Forms
Andarki namaste! User nundi input collect cheskodaniki manam HTML Forms
vaadtam. Daaniki sambandinchi coding ithe manam eeroj session lo cheseddam.
HTML Forms
HTML forms are a fundamental part of web development, allowing users to input data
and interact with a web page. Forms are used for various purposes, such as user
registration, login, search, and data submission. Below, I'll explain the key
components of an HTML form with a simple example.
<!DOCTYPE html>
<html>
<head>
<title>Sample Form</title>
</head>
<body>
<h1>Welcome to MassCoders! Please enter your details.</h1>
<form action="process_form.php" method="POST">
<!-- Text Input -->
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
Explanation:
Assignment Question:
CSS (Cascading Style Sheets) is a styling language used to control the visual
presentation of web content. There are three main ways to include CSS in your web
pages: internal, external, and inline CSS. Here are notes and examples for each:
Internal CSS:
Internal CSS is defined within the <style> element in the HTML document's <head>
section. It applies styles to a single HTML page.
<!DOCTYPE html>
<html>
<head>
<style>
/* Internal CSS */
h1 {
color: blue;
}
p {
font-size: 16px;
}
</style>
</head>
<body>
<h1>Welcome to MassCoders</h1>
<p>Subscribe to my YouTube channel</p>
</body>
</html>
External CSS:
External CSS is defined in a separate .css file and then linked to the HTML
document using the <link> element. This allows you to apply the same styles across
multiple pages.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Welcome to MassCoders</h1>
<p>Subscribe to my YouTube channel</p>
</body>
</html>
Inline CSS:
Inline CSS is defined directly within the HTML elements using the style attribute.
It's typically used for individual elements.
<!DOCTYPE html>
<html>
<body>
<h1 style="color: blue;">Welcome to MassCoders</h1>
<p style="font-size: 16px;">Subscribe to my YouTube channel</p>
</body>
</html>
In summary, the choice between internal, external, and inline CSS depends on the
scale and complexity of your project. Internal CSS is good for small-scale projects,
external CSS is ideal for larger projects with consistent styles, and inline CSS is
useful for quick and specific styling needs.
Assignment Question:
Create a basic web page that includes elements such as h1, p, div, and button tags, and
incorporate inline, internal, and external CSS to style the page.
CSS Fonts
Watch Tutorial → Click Here
CSS Fonts:
CSS (Cascading Style Sheets) allows you to control the fonts used on your webpages.
You can define fonts for various HTML elements using CSS properties.
Font Properties:
0. font-family: Specifies the font for an element. You can specify multiple fonts
as a fallback, separated by commas. The browser will use the first available
font.
1. font-family: Arial, Helvetica, sans-serif;
2.
3. font-size: Sets the size of the font. You can use different units such as pixels
(px), ems (em), or percentages (%).
4. font-size: 16px;
5.
6. font-weight: Determines the thickness or boldness of the font. Common
values include normal, bold, bolder, and numeric values from 100 to 900.
7. font-weight: bold;
8.
9. font-style: Defines the style of the font, which can be normal, italic, or
oblique.
10. font-style: italic;
11.
12. text-transform: Changes the capitalization of the text. Options include
uppercase, lowercase, and capitalize.
13. text-transform: uppercase;
14.
15. text-decoration: Adds decorations to text, like underlines or strikethrough.
Options include underline, overline, line-through.
16. text-decoration: underline;
17.
18. line-height: Sets the vertical space between lines of text. It can be defined as a
number or a unit like em or px.
19. line-height: 1.5;
20.
21. letter-spacing: Adjusts the space between characters in the text.
22. letter-spacing: 2px;
23.
24. color: Specifies the text color using various formats like color names,
hexadecimal, or RGB values.
25. color: #333;
26.
For example:
<link rel="stylesheet"
href="<https://fonts.googleapis.com/css?family=Font+Name>">
body {
font-family: 'Font Name', sans-serif;
}
32. Apply Fonts: Use the defined font in your CSS as needed for different
elements.
Google Fonts is a convenient way to enhance the typography of your web projects
with a wide range of fonts, and it ensures that the fonts are available across various
browsers.
Assignment Question:
Create a webpage that utilizes the font properties explained in this session to style text
elements. Apply different font families, sizes, weights, styles, and text
transformations to enhance the typography on your webpage. Additionally,
experiment with text decorations, line spacing, letter spacing, and text colors to create
an aesthetically pleasing and well-designed webpage.
The CSS Box Model is a fundamental concept in web design and layout. It defines
how elements are rendered on a web page by breaking down each element into four
parts: content, padding, border, and margin. These components affect the layout and
spacing of elements on a webpage. Let's explore each component with detailed
explanations and examples.
Content:
o The content area represents the actual content of the HTML element (e.g., text,
images, or other media).
o The width and height of an element are determined by its content area.
.box {
width: 200px;
height: 100px;
background-color: lightblue;
}
Padding:
o Padding is the space between the content and the element's border.
o You can set padding for individual sides (top, right, bottom, left) or all sides at
once.
.box {
padding: 20px;
background-color: lightblue;
}
Border:
.box {
padding: 20px;
border: 2px solid black;
background-color: lightblue;
}
Margin:
o The margin is the space outside the border and separates the element from
other elements on the page.
o You can set margins for individual sides or all sides at once.
o Margins can be used to control spacing between elements.
.box {
padding: 20px;
border: 2px solid black;
margin: 10px;
background-color: lightblue;
}
.box {
padding-top: 10px;
padding-right: 20px;
padding-bottom: 30px;
padding-left: 40px;
background-color: lightblue;
}
.box1 {
margin: 10px;
background-color: lightblue;
}
.box2 {
margin: 10px;
background-color: lightcoral;
}
Border Properties
In CSS, there are several properties that allow you to control the appearance and
behavior of borders around HTML elements. These properties provide you with the
flexibility to style borders in various ways. Here are some of the most commonly used
border properties in CSS:
12. border-width:
Specifies the width of the border.
You can set the width individually for each side (top, right, bottom,
left) or use the shorthand property to set all sides at once.
13. .box {
14. border-width: 2px; /* All sides */
15. border-top-width: 1px; /* Top side */
16. }
17.
18. border-style:
Defines the style of the border, such as solid, dashed, dotted, double,
etc.
19. .box {
20. border-style: solid;
21. }
22.
23. border-color:
Sets the color of the border.
24. .box {
25. border-color: red;
26. }
27.
28. border (shorthand):
Combines the border-width, border-style, and border-color
properties into a single property for convenience.
29. .box {
30. border: 2px solid red;
31. }
32.
33. border-radius:
Defines rounded corners for an element's border.
You can set the radius for each corner individually or as a single value
for all corners.
34. .box {
35. border-radius: 10px; /* All corners */
36. border-top-left-radius: 5px; /* Top-left corner */
37. }
38.
39. border-image:
Allows you to use an image as a border, creating more complex border
styles.
You can specify the image source, slice, width, outset, and repeat
values.
40. .box {
41. border-image: url(border.png) 10 10 round;
42. }
43.
CSS provides several properties to control the display and visibility of elements on a
web page. These properties allow you to show or hide elements and determine how
they are rendered within the document flow. Let's explore the display and
visibility properties with code examples.
Display Property:
The display property controls how an element is displayed in terms of its layout and
rendering. Common values include:
block: Elements are displayed as block-level elements, taking up the entire width of
their parent container.
.block {
display: block;
width: 200px;
height: 50px;
background-color: lightblue;
}
inline: Elements are displayed inline, taking up only as much width as necessary.
.inline {
display: inline;
background-color: lightcoral;
}
inline-block: Combines properties of both block and inline elements, allowing you
to set width, height, and maintain inline behavior.
.inline-block {
display: inline-block;
width: 100px;
height: 100px;
background-color: lightgreen;
}
none: The element is not displayed, and it doesn't occupy any space within the layout.
.none {
display: none;
}
Display: Flex
<!DOCTYPE html>
<html>
<head>
<style>
.flex-container {
display: flex;
justify-content: space-between;
}
.flex-item {
width: 100px;
height: 100px;
background-color: lightblue;
}
</style>
</head>
<body>
<div class="flex-container">
<div class="flex-item">1</div>
<div class="flex-item">2</div>
<div class="flex-item">3</div>
</div>
</body>
</html>
In this example, the display: flex property is applied to the .flex-container, and
justify-content: space-between is used to evenly distribute space between the
child elements.
Display: Grid
The display: grid property allows you to create two-dimensional grid layouts. You
can define rows and columns and place elements within the grid cells. Here's an
example:
<!DOCTYPE html>
<html>
<head>
<style>
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 10px;
}
.grid-item {
width: 100px;
height: 100px;
background-color: lightgreen;
}
</style>
</head>
<body>
<div class="grid-container">
<div class="grid-item">1</div>
<div class="grid-item">2</div>
<div class="grid-item">3</div>
<div class="grid-item">4</div>
<div class="grid-item">5</div>
<div class="grid-item">6</div>
</div>
</body>
</html>
In this example, the display: grid property is applied to the .grid-container, and
grid-template-columns is used to define a 3-column grid. grid-gap specifies the
gap between grid items.
Both display: flex and display: grid provide powerful layout capabilities, and
choosing one depends on your specific design requirements. Flexbox is great for one-
dimensional layouts, while grid is ideal for creating two-dimensional grid structures.
You can also combine these layout models for even more advanced layouts.
Visibility Property:
The visibility property controls the visibility of an element while still preserving
its space in the layout. Common values include:
.visible {
visibility: visible;
background-color: lightblue;
}
.hidden {
visibility: hidden;
background-color: lightcoral;
}
Assignment Question:
Design a compact webpage showcasing your preferred theme using HTML and CSS,
highlighting the practical application of the CSS Box Model, as well as the utilization
of the Display and Visibility properties.
CSS Positioning
CSS Positioning
CSS (Cascading Style Sheets) positioning allows you to control the placement of
HTML elements on a web page. There are several types of positioning in CSS,
including:
Static Positioning: This is the default positioning for all HTML elements. Elements
with static positioning are placed in the normal flow of the document. You don't need
to use any special CSS properties to create static positioning. Here's an example:
<!DOCTYPE html>
<html>
<head>
<style>
.static-box {
/* Default static positioning */
}
</style>
</head>
<body>
<div class="static-box">Static Positioning</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
.relative-box {
position: relative;
top: 20px;
left: 30px;
}
</style>
</head>
<body>
<div class="relative-box">Relative Positioning</div>
</body>
</html>
Absolute Positioning: Elements with absolute positioning are removed from the
normal document flow and are positioned relative to their closest positioned ancestor.
You can use the position: absolute property and adjust the position using top,
right, bottom, and left. Here's an example:
<!DOCTYPE html>
<html>
<head>
<style>
.container {
position: relative;
}
.absolute-box {
position: absolute;
top: 50px;
left: 50px;
}
</style>
</head>
<body>
<div class="container">
<div class="absolute-box">Absolute Positioning</div>
</div>
</body>
</html>
Fixed Positioning: Elements with fixed positioning are removed from the normal
document flow and are positioned relative to the viewport. You can use the
position: fixed property to create fixed positioning. Here's an example:
<!DOCTYPE html>
<html>
<head>
<style>
.fixed-box {
position: fixed;
top: 10px;
right: 10px;
}
</style>
</head>
<body>
<div class="fixed-box">Fixed Positioning</div>
</body>
</html>
Sticky Positioning: Elements with sticky positioning are initially positioned according
to the normal flow, but become fixed or relative to their containing block based on the
user's scroll position. You can use the position: sticky property. Here's an
example:
<!DOCTYPE html>
<html>
<head>
<style>
.sticky-box {
position: sticky;
top: 10px;
}
</style>
</head>
<body>
<div class="sticky-box">Sticky Positioning</div>
<!-- Content that causes scrolling -->
</body>
</html>
Attempt Quiz → Click Here
Assignment Question:
Create a simple webpage with the following elements positioned using CSS: A
navigation bar at the top, a main content area, and a footer at the bottom. The header
and footer should be fixed in position, while the navigation bar and main content
should be relatively positioned.
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="navbar">
<div class="navbar-left">
<img class="logo-image"
src="<https://res.cloudinary.com/nihars3/image/upload/v1695711604/oie
_4tJfBuZmsuYT_eafcem.png>" alt="logo">
</div>
<div class="navbar-right">
<a class="a-element">Home</a>
<a class="a-element">About</a>
<a class="a-element" href="#services">Services</a>
<a class="a-element">Contact</a>
</div>
</div>
<div class="home">
<div class="home-left">
<h1 class="home-h1">Dodagatta Nihar</h1>
<p class="home-p">Hello, I'm Nihar, a passionate
Bachelor's degree candidate in Artificial Intelligence at the
University of Visvesvaraya College of Engineering in Bengaluru. With
a strong background in web development and a robust portfolio of over
50 websites, I have honed my skills in creating dynamic and visually
appealing online experiences. Proficient in Python, I am adept at
leveraging its power for efficient and scalable solutions.</p>
</div>
<div class="home-right">
<img
src="<https://res.cloudinary.com/nihars3/image/upload/v1684595335/DP-
modified_vhu4ws.png>" alt="my logo">
</div>
</div>
<div class="services" id="services">
<h1 class="ser-h1">SERVICES WE OFFER</h1>
<div class="services-sub-cont">
<div class="services-card">
<h1 class="sc-h1">Web Designing</h1>
<p class="sc-p">Nenu manchi manchi websitelani design
chestha interest unte nanni sampradinchandi.</p>
</div>
<div class="services-card">
<h1 class="sc-h1">Video Editing</h1>
<p class="sc-p">Nenu manchi manchi Videos ni edit
chestha interest unte nanni sampradinchandi.</p>
</div>
<div class="services-card">
<h1 class="sc-h1">Photoshop</h1>
<p class="sc-p">Nenu manchi manchi photolani edit
chestha interest unte nanni sampradinchandi.</p>
</div>
</div>
</div>
<div class="services">
<h1 class="ser-h1">TESTIMONIALS</h1>
<div class="services-sub-cont">
<div class="services-card">
<h1 class="sc-h1">Google</h1>
<img src="<https://static-
00.iconduck.com/assets.00/google-icon-2048x2048-czn3g8x8.png>"
class="test-logo">
<p class="sc-p">Nihar manchi manchi websites naaku
design chesichadu. Pani twaraga chesthadu.</p>
</div>
<div class="services-card">
<h1 class="sc-h1">Facebook</h1>
<img src="<https://static-
00.iconduck.com/assets.00/facebook-icon-2048x2048-pth4zu2i.png>"
class="test-logo">
<p class="sc-p">Nenu manchi manchi Videos ni edit
chestha interest unte nanni sampradinchandi.</p>
</div>
<div class="services-card">
<h1 class="sc-h1">Instagram</h1>
<img src="<https://cdn-icons-
png.flaticon.com/512/1384/1384063.png>" class="test-logo">
<p class="sc-p">Nenu manchi manchi photolani edit
chestha interest unte nanni sampradinchandi.</p>
</div>
</div>
</div>
<div class="contact">
<h1 class="ser-h1">CONTACT US</h1>
<div class="contact-info">
<p>Dodagatta Nihar</p>
<p>+91 1234567890</p>
<p>[email protected]</p>
</div>
<div class="social-icons">
<div class="social-icon">
<a href="<https://www.instagram.com/niihaaarrrr/>">
<img
src="<https://upload.wikimedia.org/wikipedia/commons/thumb/5/58/Insta
gram-Icon.png/1024px-Instagram-Icon.png>" class="social-icon-img">
</a>
<a href="<https://www.youtube.com/@niharrdg>">
<img
src="<https://www.iconpacks.net/icons/2/free-youtube-logo-icon-2431-
thumb.png>" class="social-icon-img">
</a>
<a href="<https://www.linkedin.com/in/niharrdg>">
<img src="<https://cdn-icons-
png.flaticon.com/512/174/174857.png>" class="social-icon-img">
</a>
</div>
</div>
</div>
</body>
</html>
style.css:
@import
url('<https://fonts.googleapis.com/css2?family=Encode+Sans&family=Fir
a+Code&family=Fuggles&family=Montserrat:ital,wght@1,600&family=Mooli&
family=Ubuntu:ital,wght@1,500&display=swap>');@import
url('<https://fonts.googleapis.com/css2?family=Encode+Sans&family=Fir
a+Code&family=Fuggles&family=Montserrat:wght@200&family=Mooli&family=
Ubuntu:ital,wght@1,500&display=swap>');
body {
margin: 0;
background-color: black;
color: white;
}
.navbar {
display: flex;
flex-direction: row;
justify-content: space-between;
background-color: black;
}
.navbar-left {
padding-left: 50px;
}
.logo-image {
height: 100px;
}
.navbar-right {
padding-right: 20px;
display: flex;
flex-direction: row;
align-items:center;
}
.a-element {
padding: 10px;
margin: 10px;
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe
UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica
Neue', sans-serif;
font-size: 20px;
font-weight: bold;
}
.home {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
height: 85vh;
}
.home-left {
width: 50vw;
text-align: right;
padding-left: 200px;
}
.home-right {
width: 50vw;
padding-left: 100px;
}
.home-h1 {
font-family: 'Montserrat', sans-serif;
font-size: 25px;
}
.home-p {
font-family: 'Encode Sans', sans-serif;
font-size: 20px;
}
.services {
padding: 50px;
text-align: center;
}
.ser-h1 {
font-family: 'Ubuntu', sans-serif;
color: rgb(59, 211, 59);
letter-spacing: 3px;
font-size: 50px;
font-style: italic;
}
.services-sub-cont {
display: flex;
flex-direction: row;
}
.services-card {
border: 2px rgb(47, 168, 47) solid;
margin: 20px;
padding: 20px;
width: 400px;
}
.sc-h1 {
font-family: 'Montserrat', sans-serif;
font-size: 25px;
}
.sc-p {
font-family: 'Encode Sans', sans-serif;
font-size: 20px;
}
.contact {
text-align: center;
}
.contact-info {
font-family: 'Montserrat', sans-serif;
font-size: 25px;
}
.test-logo {
height: 50px;
}
.social-icon-img {
height: 50px;
padding: 20px;
}
Assignment Question:
Create a personal portfolio website incorporating the concepts we've covered so far,
and then share the screenshots or a screen recording of it with @mass_coders on
Instagram. I will review it personally and let you know what all improvements can be
made.
Introduction to Bootstrap
Introduction to Bootstrap
To get started with Bootstrap, you need to include its CSS and JavaScript files in your
HTML document. You can either download the Bootstrap files and host them on your
server, or you can link to the Bootstrap CDN (Content Delivery Network) for a
quicker setup. Here's how to include Bootstrap via CDN:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-
scale=1">
<title>Bootstrap demo</title>
<link
href="<https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstra
p.min.css>" rel="stylesheet" integrity="sha384-
T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN"
crossorigin="anonymous">
</head>
<body>
<h1>Hello, world!</h1>
<script
src="<https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.
bundle.min.js>" integrity="sha384-
C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
crossorigin="anonymous"></script>
</body>
</html>
Navbar
A Bootstrap navbar is a navigation bar that can be easily created using Bootstrap's
navigation components. Here's an example of a simple navbar:
Buttons
Bootstrap provides various button styles and sizes. Here's how to create different
types of buttons:
Carousel
Cards
Bootstrap cards are versatile components for displaying various types of content.
Here's an example of a Bootstrap card:
These are just the basics of Bootstrap. Bootstrap offers a wide range of components
and utility classes to make your web development process faster and more responsive.
You can explore the Bootstrap documentation for more details and customization
options: https://getbootstrap.com/
Attempt Quiz → Click Here
Assignment Question:
Make a small website of your theme using the topics covered today.
Code: index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>MassCoders</title>
<link rel="stylesheet" href="./massstyle.css" type="text/css">
<link rel="icon"
href="<https://res.cloudinary.com/nihars3/image/upload/v1695711604/oi
e_4tJfBuZmsuYT_eafcem.png>" type="image/x-icon">
<link
href="<https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstra
p.min.css>" rel="stylesheet" integrity="sha384-
T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN"
crossorigin="anonymous">
<script
src="<https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.
min.js>" integrity="sha384-
BBtl+eGJRgqQAUMxJ7pMwbEyER4l1g+O15P+16Ep7Q9Q+zqX6gSbd85u4mG4QzX+"
crossorigin="anonymous"></script>
<script
src="<https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.
bundle.min.js>" integrity="sha384-
C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
crossorigin="anonymous"></script>
</head>
<body>
<div class="mass-body">
<div class="navbar-section">
<nav class="navbar navbar-expand-lg">
<div class="container-fluid mass-nav pl-5 pr-5">
<img
src="<https://res.cloudinary.com/nihars3/image/upload/v1695711604/oie
_4tJfBuZmsuYT_eafcem.png>" class="mass-logo">
<button class="navbar-toggler d-none" type="button"
data-bs-toggle="collapse" data-bs-target="#navbarNavAltMarkup" aria-
controls="navbarNavAltMarkup" aria-expanded="false" aria-
label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse"
id="navbarNavAltMarkup">
<div class="navbar-nav anchor">
<a class="nav-link mass-anchor"
href="#about">About</a>
<a class="nav-link mass-anchor"
href="#courses">Courses</a>
<a class="nav-link mass-anchor"
href="#workshops">Workshops</a>
<a class="nav-link mass-anchor"
href="#contact">Contact</a>
</div>
</div>
</div>
</nav>
</div>
<div class="body-section">
<div class="container-fluid">
<div class="row d-flex flex-row justify-content-
center">
<!-- Left Half - Information About Me -->
<div class="col-12 order-1 order-md-1 col-md-6
left-body">
<h1 class="mass-nihar">DODAGATTA <span
style="color: rgb(57, 211, 57);">NIHAR</span></h1>
<p class="mass-nihar-para">I'm Nihar, a
versatile tech enthusiast with a strong commitment to knowledge
sharing and innovation. I wear multiple hats as a YouTuber and
Instagram tech influencer, where I focus on teaching coding, MERN
Stack development, and engaging in in-depth discussions about the
ever-evolving tech landscape. My genuine love for AI adds an extra
layer of excitement to my tech journey. I'm always eager to connect
with fellow tech enthusiasts, creators, and professionals who share
my passion for technology, learning, and growth.</p>
</div>
<!-- Right Half - My Photo -->
<div class="col-12 order-0 order-md-2 col-md-4">
<img
src="<https://res.cloudinary.com/nihars3/image/upload/v1698579978/tem
pImagewwyH9B-modified_kzi10d.png>" alt="Dodagatta Nihar" class="img-
fluid">
</div>
</div>
</div>
</div>
<div class="what-we-do pt-5" id="about">
<div class="container">
<h2 class="about-h1">about <span style="color:
rgb(57, 211, 57);">us</span></h2>
<p class="about-p">MassCoders, founded by Dodagatta
Nihar in July 2023, is a visionary community with a mission to
empower and inspire the youth to explore the world of coding. Our
motto, "Motivating youth to code," encapsulates our dedication to
making coding accessible and engaging for all, especially in native
languages such as Telugu and expanding to Kannada.
</p>
</div>
</div>
<div class="what-we-do" id="whatwedo">
<div class="container">
<h2 class="about-h1">what we <span style="color:
rgb(57, 211, 57);">do</span>?</h2>
<p class="about-p">We specialize in providing coding
tutorials in native languages, starting with Telugu, and extending
our reach to Kannada. At MassCoders, we believe that learning to code
should be inclusive and easy to understand, regardless of one's
linguistic background.
</p>
</div>
</div>
<div class="courses-offered" id="courses">
<div class="container">
<h2 class="text-center about-h1">courses <span
style="color: rgb(57, 211, 57);">offered</span></h2>
<div class="row">
<!-- Course 1 -->
<div class="col-12 col-md-6">
<div class="course-card">
<a
href="<https://youtu.be/Ywfuw4SUDv8?si=cAAYSrz3RX4ONouu>"
style="text-decoration: none;">
<div>
<img
src="<https://res.cloudinary.com/nihars3/image/upload/v1696239218/Web
_Development_with_MERN-2_wdcl1r.png>" alt="Course 1">
<h3 class="course-title">Web
development with <span style="color: rgb(57, 211,
57);">MERN</span></h3>
<p class="course-p">In my
specialized web development course, I offer comprehensive tutorials
in the Telugu language, focusing on the MERN (MongoDB, Express.js,
React, Node.js) stack. With a deep commitment to clarity, I provide
detailed explanations of every topic covered. You'll find in-depth
notes accompanying the tutorials, serving as a valuable resource for
your learning journey. To reinforce your understanding, I've included
quizzes and practice questions to help you apply your knowledge
effectively. Whether you're a beginner or an aspiring developer
looking to enhance your skills, this course is designed to empower
you with the tools and expertise you need for success in web
development.
</p>
</div>
</a>
</div>
</div>
<!-- Course 2 -->
<div class="col-12 col-md-6">
<div class="course-card">
<a
href="<https://www.instagram.com/p/CvM4jVBp8F3/>" style="text-
decoration: none;">
<div>
<img
src="<https://res.cloudinary.com/nihars3/image/upload/v1696239443/Cop
y_of_Web_Development_with_MERN_eclmlb.png>" alt="Course 2">
<h3 class="course-title">Python
on <span style="color: rgb(57, 211, 57);">IG Reels</span></h3>
<p class="course-p">In my
Instagram Reels Python course taught in Telugu, I'll help you learn
Python easily. I provide clear and concise notes that explain the
basics of Python step by step. To make sure you really understand, I
include lots of practice questions that will help you get better at
solving problems. Whether you're a beginner or someone who wants to
get better at Python, this course is designed to help you. You'll
gain practical skills that will make you confident in Python
programming.</p>
</div>
</a>
</div>
</div>
</div>
</div>
</div>
<div class="workshops" id="workshops">
<div class="container">
<h2 class="text-center about-h1">access<span
style="color: rgb(57, 211, 57);"> notes</span></h2>
<a class="d-flex flex-row justify-content-center
link-span" target="_blank"
href="<https://masscoders.notion.site/masscoders/Web-Development-
with-MERN-eba16384715f473b95f25ab1ea050bc0>">
<div class="text-center">
<img class="course-logo" src="<https://cdn-
icons-png.flaticon.com/512/2210/2210184.png>">
</div>
<p class="pandaga-p text-center">Web
Development</p>
</a>
<a class="d-flex flex-row justify-content-center
link-span" target="_blank"
href="<https://masscoders.notion.site/Muppai-rojullo-Python-
2f54ed7ca67e4d21a52eb60a3927b9e4?pvs=4>"">
<div class="text-center">
<img class="course-logo"
src="<https://upload.wikimedia.org/wikipedia/commons/thumb/c/c3/Pytho
n-logo-notext.svg/1869px-Python-logo-notext.svg.png>">
</div>
<p class="pandaga-p text-center">Python</p>
</a>
</div>
</div>
<div class="workshops" id="workshops">
<div class="container">
<h2 class="text-center about-h1">work<span
style="color: rgb(57, 211, 57);">shops</span></h2>
<h2 class="text-center" style="font-size:
30px;">coming<span style="color: rgb(57, 211, 57);">
sooooooooon!</span></h2>
</div>
</div>
<div class="contact pb-5" id="contact">
<div class="container text-center">
<h2 class="about-h1">contact<span style="color:
rgb(57, 211, 57);"> us</span></h2>
<p class="about-p">You can reach us via <span
style="color: rgb(57, 211, 57);">email</span> and follow us on <span
style="color: rgb(57, 211, 57);">social media</span>.</p>
<!-- Email -->
<p class="about-p"><strong>Email:</strong> <a
href="mailto:[email protected]" style="color: rgb(57, 211, 57);
text-decoration: none;">[email protected]</a></p>
<!-- Social Media Links -->
<ul class="list-inline">
<li class="list-inline-item">
<a
href="<https://www.instagram.com/niihaaarrrr/>" target="_blank"
rel="noopener noreferrer">
<img
src="<https://upload.wikimedia.org/wikipedia/commons/thumb/a/a5/Insta
gram_icon.png/600px-Instagram_icon.png?20200512141346>"
alt="Instagram" class="social-icon">
</a>
</li>
<li class="list-inline-item">
<a
href="<https://www.linkedin.com/in/niharrdg/>" target="_blank"
rel="noopener noreferrer">
<img src="<https://cdn-icons-
png.flaticon.com/512/174/174857.png>" alt="LinkedIn" class="social-
icon">
</a>
</li>
<li class="list-inline-item">
<a href="<https://t.me/masscoders>"
target="_blank" rel="noopener noreferrer">
<img src="<https://static-
00.iconduck.com/assets.00/telegram-icon-2048x2048-l6ni6sux.png>"
alt="Telegram" class="social-icon">
</a>
</li>
</ul>
</div>
</div>
<script
src="<https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/pop
per.min.js>" integrity="sha384-
I7E8VVD/ismYTF4hNIPjVp/Zjvgyol6VFvRkX/vR+Vc4jQkC+hVqc2pM8ODewa9r"
crossorigin="anonymous"></script>
</body>
</html>
massstyle.css:
* {
color: white;
}
.anchor {
margin-left: auto;
}
.mass-logo {
height: 100px;
padding-left: 20px;
}
.mass-anchor {
color: white !important;
padding-right: 20px !important;
font-family: 'Poppins', sans-serif;
}
.mass-anchor:hover {
color: rgb(40, 214, 40) !important;
transform: scale(1.09);
}
.mass-nihar {
font-family: 'Encode Sans', sans-serif;
letter-spacing: 4px;
font-size: 50px;
}
.mass-nihar-para {
font-family: 'Gabarito', cursive;
font-size: 20px;
}
.mass-body {
background-image:
url('<https://res.cloudinary.com/nihars3/image/upload/v1696232927/pho
to-1619429858348-2d5ad1547e6c_nnvynb.jpg>');
background-size: cover;
height: auto;
}
.left-body {
padding-left: 100px !important;
color: white;
padding-top: 40px !important;
}
.body-section {
padding-top: 100px;
text-align: center;
height: 80vh;
}
.link-span {
text-decoration: none !important;
color: rgb(40, 214, 40) !important;
}
.what-we-do {
color: white;
text-align: center;
padding-bottom: 20px;
padding-left: 150px;
padding-right: 150px;
}
.about-h1 {
font-family: 'DM Sans', sans-serif;
font-size: 50px;
}
.about-title {
font-family: 'DM Sans', sans-serif;
font-size: 30px;
}
.course-title {
font-family: 'DM Sans', sans-serif;
font-size: 25px;
padding-top: 20px;
}
.about-p {
font-family: 'Montserrat', sans-serif;
font-size: 25px;
}
.pandaga-p {
font-family: 'Montserrat', sans-serif;
font-size: 25px;
}
.pandaga-p:hover {
color: rgb(40, 214, 40) !important;
}
.course-p {
font-family: 'Montserrat', sans-serif;
font-size: 18px;
max-width: 590px;
}
.course-card {
border: 1px solid #ccc;
transition: all 0.3s;
margin-bottom: 20px;
padding: 20px;
text-align: center;
min-height: 800px;
padding: 10px;
}
.course-card img {
max-width: 100%;
height: auto;
}
.course-card:hover {
border: 2px solid green;
transform: scale(1.05);
}
.course-logo{
height: 40px;
padding-right: 10px;
}
.social-icon {
height: 50px;
padding-right: 20px;
}
.mass-anchor {
padding-right: 10px !important;
font-size: 14px;
}
.mass-nihar {
font-size: 40px;
text-align: center;
}
.mass-nihar-para {
font-size: 16px;
text-align: center;
}
.body-section {
padding-top: 50px;
}
.what-we-do {
padding-left: 20px;
padding-right: 20px;
}
.about-h1 {
font-size: 40px;
}
.about-title {
font-size: 24px;
}
.course-title {
font-size: 20px;
}
.about-p {
font-size: 20px;
}
.course-p {
font-size: 16px;
max-width: 100%;
}
.course-card {
min-height: auto;
padding: 10px;
}
.body-section {
height: auto;
}
.left-body {
padding-left: 0px !important;
padding: 20px !important;
}
}
Git and GitHub are essential tools for version control and collaboration in software
development.
Git:
Git is a distributed version control system (DVCS) used for tracking changes in
source code during software development. It allows multiple developers to collaborate
on the same project efficiently.
1. Version Control:
o Git enables developers to track changes in their code over time, providing a
complete history of modifications.
2. Distributed:
o Git is a distributed version control system, meaning that each developer has a
full copy of the repository, allowing them to work offline and independently.
4. Local Repository:
o Git operates locally on your machine, which means you can commit changes
and experiment without affecting the central repository until you choose to
push your changes.
5. Commit History:
o Git keeps a record of every change made to the codebase, making it easy to
trace back and understand the evolution of the project.
GitHub:
GitHub is a web-based platform that hosts Git repositories, providing a central
location for collaboration, code hosting, and project management.
1. Centralized Collaboration:
2. Code Hosting:
Developers can store their code in GitHub repositories, making it accessible from
anywhere with an internet connection.
3. Issue Tracking:
GitHub's issue tracker allows teams to report, track, and manage tasks, bugs, and
feature requests in an organized manner.
4. Pull Requests:
Pull requests in GitHub facilitate code review and collaboration by proposing and
discussing changes before merging them into the main codebase.
5. Workflow Automation:
GitHub Actions enables automation of tasks like building, testing, and deploying
code, streamlining the development process.
6. Documentation:
7. Project Management:
GitHub Projects allows for the organization and prioritization of work using
customizable boards, making it easier to manage tasks and milestones.
GitHub provides both public and private repositories, allowing projects to be shared
openly or kept confidential, depending on the needs of the developers.
Notes:
o GitHub is not the only platform for hosting Git repositories. Alternatives
include GitLab and Bitbucket.
o Collaborators can work together on a project by forking a repository and
creating pull requests.
o GitHub offers free public repositories, but private repositories require a
subscription.
GitHub serves as a hub for developers, providing tools and features that enhance
collaboration, code management, and project organization, while Git itself underlies
version control and allows for efficient tracking of code changes. Together, Git and
GitHub support effective software development and project management.
Installing Git:
1. Mac:
o Homebrew:
o /bin/bash -c "$(curl -fsSL
<https://raw.githubusercontent.com/Homebrew/install/HEAD/instal
l.sh>)"
o brew install git
o
o Xcode Command Line Tools:
o xcode-select --install
o
2. Linux (Ubuntu/Debian):
sudo apt update
sudo apt install git
3. Windows:
Download and install Git from the official website: Git for Windows
Hosting on GitHub:
o Go to GitHub.
o Click on the "+" sign in the top right and choose "New repository".
o Follow the instructions to create a new repository.
4. Verify on GitHub:
Refresh your GitHub repository page, and you should see your files.
These instructions assume you are using HTTPS for simplicity. If you set up SSH
keys, you can use the SSH URL instead of the HTTPS URL when adding the remote.
Additionally, replace "your-username" and "your-repo" with your GitHub username
and the name of your repository.
Introduction to JavaScript
Introduction to JavaScript
1. What is JavaScript?
2. History of JavaScript:
4. Features of JavaScript:
6. DOM Manipulation:
o JavaScript is used to manipulate the Document Object Model (DOM) of a web
page.
o It can change HTML elements, attributes, and styles dynamically, making web
pages interactive.
Variables in JavaScript:
Variables in JavaScript are used to store data values. You can think of them as
containers that hold different types of information. To declare a variable in JavaScript,
you can use the var, let, or const keywords.
0. var :
var was traditionally used for variable declaration, but it has some
scope issues and is less commonly used now.
1. var age = 19; // Declaring a variable 'age' and assigning it a
value of 19
2. age = 20; // You can change the value of a 'var' variable
3.
4. let:
let allows you to declare block-scoped variables, which means they
are only accessible within the block (e.g., inside a function or loop)
where they are defined.
5. let name = "Dodagatta Nihar";
6. let age = 19;
7.
8. const:
const is used to declare constants. Once a value is assigned to a
const, it cannot be changed.
9. const pi = 3.14159;
10.
JavaScript has several data types to represent different kinds of values. These data
types include:
a. String:
b. Number:
c. Boolean:
Represents true or false values.
d. Undefined:
Represents a variable that has been declared but hasn't been assigned a
value.
let x;
console.log(x); // This will output 'undefined'
e. Null:
a. Object:
let person = {
name: "Bob",
age: 30,
};
b. Array:
c. Function:
function greet(name) {
return `Hello, ${name}!`;
}
These are the fundamental concepts of variables and data types in JavaScript.
Understanding these concepts is essential for writing effective and flexible JavaScript
code.
Assignment Questions:
Arithmetic Operators:
Comparison Operators:
Comparison operators in JavaScript are used to compare values and return Boolean
results (true or false). Here are some common comparison operators:
20. Equal (==): Checks if two values are equal, but it doesn't consider data types
(type coercion).
21. 5 == "5"; // true (values are equal, type coercion)
22.
23. Not Equal (!=): Checks if two values are not equal, with type coercion.
24. 5 != "3"; // true (values are not equal, type coercion)
25.
26. Strict Equal (===): Checks if two values are equal and have the same data
type (no type coercion).
27. 5 === 5; // true (values and data types are equal)
28.
29. Strict Not Equal (!==): Checks if two values are not equal or have different
data types.
30. 5 !== "5"; // true (values are not equal or have different
data types)
31.
32. Greater Than (>): Checks if the left value is greater than the right value.
33. 10 > 5; // true
34.
35. Less Than (<): Checks if the left value is less than the right value.
36. 3 < 7; // true
37.
38. Greater Than or Equal (>=): Checks if the left value is greater than or equal
to the right value.
39. 10 >= 10; // true
40.
41. Less Than or Equal (<=): Checks if the left value is less than or equal to the
right value.
42. 3 <= 3; // true
43.
These operators are crucial for performing comparisons and making decisions in your
JavaScript code. Understanding how to use them effectively is fundamental for
writing robust programs.
Assignment Questions:
44. Code a statement that adds 5 and 7. Assign the result to a variable called sum.
45. Write a line of code that subtracts 3 from 10. Store the result in a variable
named difference.
46. Use JavaScript to multiply 4 by 6. Save the product in a variable called
product.
47. Create a line of code that divides 15 by 3. Save the quotient in a variable
named quotient.
48. Write a statement that checks if 8 is equal to "8". Store the result in a variable
named isEqual.
49. Code a line that verifies if 10 is greater than 5. Save the result in a variable
named isGreaterThan.
50. Implement a statement that checks if 6 is not equal to 6. Store the result in a
variable named isNotEqual.
Logical Operators
Logical Operators
The && operator returns true if both of its operands are true. If at least one of the
operands is false, it returns false.
let result1 = isTrue && isTrue; // true (both operands are true)
let result2 = isTrue && isFalse; // false (one operand is false)
let result3 = isFalse && isFalse; // false (both operands are false)
2. Logical OR (||):
The || operator returns true if at least one of its operands is true. If both operands
are false, it returns false.
You can combine logical operators to create more complex conditions. Parentheses
are often used to control the order of evaluation.
let x = 5;
let y = 10;
let isGreater = (x > y) && (x !== 0); // false (both conditions must
be true)
let isEither = (x < y) || (y === 10); // true (at least one condition
must be true)
let isNotZero = !(x === 0); // true (negating a false condition)
Assignment Questions:
Conditional Statements
Conditional Statements
Conditional statements in JavaScript allow you to control the flow of your program
based on certain conditions. They enable you to make decisions and execute different
blocks of code depending on whether a condition is true or false. There are three
primary conditional statements in JavaScript: if, else if, and else. Let's explore
them with examples:
1. The if Statement:
The if...else statement is used when you want to execute one block of code if a
condition is true, and another block if it's false.
The else if statement allows you to specify multiple conditions to check. It's often
used in conjunction with if...else statements.
if (isWeekend) {
if (time < 12) {
console.log("Good morning on the weekend!");
} else {
console.log("Good afternoon on the weekend!");
}
} else {
if (time < 12) {
console.log("Good morning on a weekday!");
} else {
console.log("Good afternoon on a weekday!");
}
}
Ternary Operator:
JavaScript also provides a concise way to write simple conditional statements using
the ternary operator (? :).
Assignment Questions:
Loops in JavaScript
Loops
In JavaScript, loops are used to execute a block of code repeatedly. There are several
types of loops in JavaScript, but the most common ones are for loops, while loops,
and do...while loops. Let's explore these loops with examples:
1. for Loop:
The for loop is used when you know how many times you want to repeat a block of
code. It consists of three parts: initialization, condition, and increment/decrement.
This loop will execute the code block five times, starting from i = 0, incrementing i
by 1 with each iteration until the condition (i < 5) is no longer true.
2. while Loop:
The while loop is used when you don't know in advance how many times you want to
repeat a block of code. It continues as long as a specified condition is true.
let count = 0;
This loop will execute the code block as long as the condition count < 5 remains
true.
3. do...while Loop:
The do...while loop is similar to the while loop, but it always executes the code
block at least once before checking the condition.
let x = 0;
do {
console.log("x is: " + x);
x++;
} while (x < 5);
This loop first executes the code block and then checks the condition x < 5. If it's
true, the loop continues; otherwise, it stops.
JavaScript provides loop control statements that allow you to control the flow of
loops:
Loops are essential for iterating over arrays, processing data, and performing
repetitive tasks in your JavaScript programs. Understanding how to use loops
effectively is a fundamental skill for any JavaScript developer.
Assignment Questions:
2. Write a for loop that prints all even numbers from 0 to 10.
3. Initialize an array of 5 fruits. Use a for loop to print all the elements.
4. Take an array of numbers as input. Use a do-while loop to compute their sum
by iterating over the array (hint: arrayname.length).
5. Write a loop that iterates from 7 to 77 and prints only those numbers which are
multiples of 7. (use the modulus operator %)
6. Use nested for loops to print the following pattern:
*
* *
* * *
* * * *
* * * * *
Arrays in JavaScript
Arrays
Arrays in JavaScript are a data structure used to store collections of values in a single
variable. You can access the elements in an array by their index, and arrays are very
versatile and widely used in JavaScript for a variety of tasks.
To declare and initialize an array in JavaScript, you can use square brackets to enclose
the array elements. Here's an example:
Array Methods
0. Push Method:
The push method adds one or more elements to the end of an array and returns
the new length of the array.
fruits.push('elderberry');
console.log(fruits); // Output: ['apple', 'banana', 'cherry',
'date', 'elderberry']
1. Pop Method:
The pop method removes the last element from an array and returns that
element.
2. Shift Method:
The shift method removes the first element from an array and returns that
element.
3. Unshift Method:
The unshift method adds one or more elements to the beginning of an array
and returns the new length of the array.
fruits.unshift('apricot', 'fig');
console.log(fruits); // Output: ['apricot', 'fig', 'banana',
'cherry', 'date']
Assignment Questions:
4. Create an array called "fruits" and add 3 fruits to it using the push() method.
Then remove the last fruit using the pop() method and display the updated
array.
5. Create an array called "vegetables" with 5 items. Remove the first item using
shift() and add a new item to the beginning using unshift(). Display the
updated array.
6. Create an array called "nums" with numbers 1-5. Using a loop, remove all
existing items and add numbers 6-10 using the push() method. Display the
final array.
7. Create an array called "strings" with 5 string values. Using push() and
unshift(), add 2 items to beginning and end. Using pop() and shift(), remove 2
items from beginning and end. Display array after each operation.
The concat method is used to merge two or more arrays and returns a new array.
slice Method:
The slice method extracts a section of an array and returns it as a new array.
splice Method:
The splice method can be used to add, remove, or replace elements within an array.
indexOf Method:
The indexOf method returns the first index at which a given element is found in the
array, or -1 if it is not present.
filter Method:
The filter method creates a new array with all elements that pass a test implemented
by a provided function.
forEach Method:
The forEach method allows you to iterate over the elements of an array and execute a
function for each element.
map Method:
The map method creates a new array by applying a function to each element of the
original array.
find Method:
The find method returns the first element in an array that satisfies a provided testing
function.
sort Method:
The sort method is used to sort the elements of an array in place and return the sorted
array.
Assignment Questions:
0. Create an array of 5 student names. Take a new input student name from the
user and add it to the existing array using concat(). Display the final array.
1. Create an array of length 10 with random numbers between 1-100. Take a
slice of this array to select only last 5 elements. Display the sliced array.
2. Create an array of 6 fruits with "apple" as one of them. Use indexOf() to find
position of "apple". Display the index or display "apple not found".
3. Create an array of even numbers from 2 to 20. Using filter(), create new array
with only numbers greater than 10. Display filtered array.
4. Create an array to store 5 random country names. Sort the array in ascending
alphabetical order using sort() method. Display final array.
Functions Part-1
0. Function Declaration:
function greet(name) {
console.log(`Hello, ${name}!`);
}
1. Function Parameters:
Functions can take parameters (inputs) and use them within the function's
body.
function add(a, b) {
return a + b;
}
2. Function Expression:
3. Arrow Functions:
Arrow functions provide a concise syntax for defining functions, especially for
one-liners.
4. Return Statement:
Functions can return values using the return statement. If a function doesn't
explicitly return a value, it returns undefined.
function sayHello() {
return 'Hello!';
}
Assignment Questions:
5. Write a function addNumbers that takes two numbers as arguments and returns
their sum. Call the function to find sum of any two numbers and display the
result.
6. Write an arrow function square that takes a number and returns its square.
Call this function to find square of any number and display the result.
7. Write a function expression called randomNumber that returns a random whole
number between 1 and 10. Assign this function to a variable and display
output of that variable to see random numbers.
8. Write a function stringConcat that takes two string arguments and returns
concatenated string. Call this function to concatenate your first and last name
into a full name. Display the returned full name.
9. Write a function greetUser that takes username as input parameter and
returns a greeting text for that user. Call the function for at least 3 different
users and display their customized greetings.
Functions Part-2
0. Function Scope:
Variables declared inside a function are scoped to that function and not
accessible from outside.
function outerFunction() {
let message = 'I am inside the function';
console.log(message);
}
outerFunction();
console.log(message); // Error: message is not defined
1. Closures:
A closure is a function that "remembers" its lexical scope, even when called
outside that scope.
function outer() {
let message = 'Hello';
function inner() {
console.log(message);
}
return inner;
}
2. Callbacks:
function fetchData(callback) {
// Simulate an asynchronous operation
setTimeout(function() {
let data = 'This is the data';
callback(data);
}, 2000);
}
function displayData(data) {
console.log(data);
}
// Named function
function namedFunction() {
console.log('I am named');
}
function hoistedFunction() {
console.log('I am hoisted');
}
Assignment Questions:
5. Write a function that uses a closure to create a counter. The function should
return a new function that when invoked increments and returns a counter
variable.
6. Write a function outer which returns an anonymous inner function that
changes a variable message when called. Call the inner function and display
the changed message outside outer.
7. Write an asynchronous function fakeFetch that accepts a callback. Use
setTimeout inside fakeFetch to simulate a 2 second asynchronous operation
before calling the callback function.
8. Write both a named and an anonymous function to print your name. Store
them in variables and call both functions.
9. Write a program with a function called hoisted and call that function before
declaring it to see hoisting in action.
OOP Part-1
1. Objects: Objects are the basic building blocks of OOP. They represent real-world
entities, combining data (attributes) and behavior (methods or functions) into a single
unit. Objects are instances of classes.
Sure, let's illustrate some of the basic Object-Oriented Programming (OOP) concepts
with a simple example in JavaScript:
// Method to greet
greet() {
console.log(`Hello, my name is ${this.name} and I am ${this.age}
years old.`);
}
}
In this example:
0. We define a class called Person with a constructor that initializes name and
age properties.
1. The greet method is a function associated with the Person class.
2. We create two objects, person1 and person2, each with their own set of
properties.
3. We access object properties and call the greet method to display a message
specific to each object.
This example demonstrates key OOP concepts, such as classes, objects, properties,
and methods. The Person class acts as a blueprint for creating objects, and objects
have their own data (properties) and behavior (methods). It's a simple illustration of
how OOP promotes code organization and the modeling of real-world entities in your
code.
“this” operator:
In JavaScript, the this operator is typically used in the constructor of a class to refer
to the current instance of the object being created. It's used to initialize and assign
values to the object's properties. While it's common and standard practice to use this
in constructors, it is not strictly necessary to do so, especially if you are not using
object-oriented programming principles.
However, when you are using the class syntax in JavaScript to define constructors and
methods, it is recommended and standard to use this to reference the instance's
properties. This ensures clarity and consistency in your code, making it easier to
understand and maintain.
If you decide not to use this in the constructor, you would have to come up with an
alternative approach to initialize and assign values to the object's properties, which
can make your code less conventional and less readable.
Here's an example of a constructor without using this, though it's not a common
practice:
class Person {
constructor(name, age) {
const person = {};
person.name = name;
person.age = age;
return person;
}
greet() {
console.log(`Hello, my name is ${this.name} and I am ${this.age}
years old.`);
}
}
In this example, the constructor creates a new object (person) and returns it, which is
a less common and less conventional approach. It's typically recommended to use
this in the constructor for better code organization and maintainability.
Assignment Question:
OOP Part-2
1. Objects:
In JavaScript, objects are collections of key-value pairs. They are used to represent
and organize data. Objects can contain various data types, including other objects,
functions, and primitive values. Here's how you can create an object:
let person = {
firstName: "Nihar",
lastName: "Dodagatta",
age: 20
};
2. Properties:
Properties are the key-value pairs within an object. They define the characteristics or
attributes of the object. You can access object properties using dot notation or bracket
notation:
3. Methods:
Methods are functions defined as properties of an object. They allow you to perform
actions or operations on the object's data. Here's how you can define and use a method
within an object:
let calculator = {
add(a, b) {
return a + b;
},
subtract(a, b) {
return a - b;
}
};
let circle = {
radius: 5,
area() {
return Math.PI * this.radius * this.radius;
}
};
5. Object Constructors:
You can create multiple objects with the same structure and methods by using
constructor functions or classes. Constructor functions are functions that are used to
create objects with similar properties and methods. Here's an example of an object
created using a constructor function:
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
getFullName() {
return `${this.firstName} ${this.lastName}`;
}
}
Assignment Question:
o length
o width
Then create a Rectangle object to represent a rectangle with length = 5 and width = 3.
Call the area() and perimeter() methods on the rectangle object and log the results to
display the area and perimeter of the rectangle.
o Creating an object
o Using properties
o Defining and calling methods
o Using this keyword
4. Properties and Methods: Every node in the DOM tree has properties and methods
that can be accessed and called using scripting languages. These properties allow you
to access attributes and content, while methods enable you to modify or interact with
the content.
7. Use Cases: The DOM is used for various purposes in web development, such as:
These are the basics of selecting and manipulating HTML elements with JavaScript.
The combination of selecting the right element and using the appropriate methods
allows you to create dynamic and interactive web pages. It's essential to understand
the DOM and how JavaScript interacts with it to build effective and responsive web
applications.
Assignment Question:
Write a JavaScript code that does the following when the button is clicked:
o getElementById()
o querySelector()
o textContent
o setAttribute()
o style
1. Accessing Elements:
<!DOCTYPE html>
<html>
<body>
<h1 id="myHeading">Hello, DOM!</h1>
<p>This is a simple example.</p>
<script>
// Accessing an element by its ID
const heading = document.getElementById("myHeading");
console.log(heading.innerHTML); // Output: "Hello, DOM!"
</script>
</body>
</html>
2. Manipulating Content:
You can change the content and attributes of HTML elements dynamically. Here's an
example of changing the text of a paragraph element:
<!DOCTYPE html>
<html>
<body>
<p id="myParagraph">This is a paragraph.</p>
<script>
// Changing the text of a paragraph element
const paragraph = document.getElementById("myParagraph");
paragraph.innerHTML = "This is a new paragraph text.";
</script>
</body>
</html>
3. Handling Events:
You can attach event handlers to HTML elements to respond to user interactions.
Here's an example of adding a click event handler to a button:
<!DOCTYPE html>
<html>
<body>
<button id="myButton">Click me</button>
<script>
// Adding a click event handler
const button = document.getElementById("myButton");
button.addEventListener("click", function() {
alert("Button clicked!");
});
</script>
</body>
</html>
The DOM allows you to create dynamic user interfaces. Here's an example of a
simple counter that increments when a button is clicked:
<!DOCTYPE html>
<html>
<body>
<p>Counter: <span id="counter">0</span></p>
<button id="incrementButton">Increment</button>
<script>
// Creating a dynamic interface
const counter = document.getElementById("counter");
const incrementButton =
document.getElementById("incrementButton");
let count = 0;
incrementButton.addEventListener("click", function() {
count++;
counter.innerHTML = count;
});
</script>
</body>
</html>
These examples demonstrate how the DOM can be used to access elements,
manipulate content, handle events, and create dynamic web interfaces in web
development. JavaScript, in conjunction with the DOM, provides the tools for making
web pages interactive and responsive to user interactions.
Assignment Question:
This will allow users to add list items by entering text and clicking the add button.
o document.getElementById()
o .value
o document.createElement()
o .appendChild()
o addEventListener()
Test your code by adding a few list items and ensuring they get appended to the
unordered list on button click.
Event Handling
Event Handling
1. Event Types:
JavaScript supports a wide range of events that can occur in a web page. Some
common event types include:
2. Event Listeners:
Event listeners are used to "listen" for specific events on HTML elements and trigger
a specified function (the event handler) when the event occurs. You can add event
listeners using the addEventListener method.
button.addEventListener("click", function(event) {
// Event handling code
});
3. Event Object:
When an event occurs, an event object is automatically passed to the event handler as
a parameter. This object contains information about the event, such as the target
element, event type, mouse position, and more.
element.addEventListener("click", function(event) {
console.log("Event type: " + event.type);
console.log("Target element: " + event.target);
console.log("Mouse X: " + event.clientX);
console.log("Mouse Y: " + event.clientY);
});
You can also remove event listeners if they are no longer needed using the
removeEventListener method.
element.removeEventListener("click", eventHandler);
5. Event Propagation:
Events in the DOM can propagate in two phases: capturing phase and bubbling phase.
The default behavior is the bubbling phase, where the event starts at the target
element and bubbles up the DOM tree to the root. You can control the event
propagation using the stopPropagation method.
6. Event Delegation:
Event delegation is a technique where you attach a single event listener to a common
ancestor of multiple elements. This is particularly useful for handling events on
dynamically generated elements or a large number of elements efficiently.
document.getElementById("parentElement").addEventListener("click",
function(event) {
if (event.target.classList.contains("dynamicElement")) {
// Event handling for dynamically generated elements
}
});
<!DOCTYPE html>
<html>
<body>
<button id="myButton">Click Me</button>
<script>
const button = document.getElementById("myButton");
function handleClick(event) {
console.log("Button clicked!");
// Access event properties, e.g., event.target, event.type
}
button.addEventListener("click", handleClick);
</script>
</body>
</html>
This example adds a click event listener to a button, which calls the handleClick
function when the button is clicked. Understanding event handling is crucial for
creating interactive and responsive web applications.
Assignment Question:
10. Create an HTML file with a button element with the id "myButton" and text
"Click Me."
11. In the same HTML file, add a script tag to write JavaScript code.
12. Use JavaScript to add an event listener to the button so that when it's clicked, a
function called handleButtonClick is executed.
13. In the handleButtonClick function, log the message "Button clicked!" to the
console.
What is a Promise?
Creating a Promise:
// Example of a Promise
let myPromise = new Promise((resolve, reject) => {
// Asynchronous operation (e.g., fetching data, reading a file)
let operationSuccessful = true; // Set to false for demonstration
purposes
if (operationSuccessful) {
// If successful, call 'resolve' with the result
resolve("Operation completed successfully!");
} else {
// If failed, call 'reject' with the reason
reject("Operation failed!");
}
});
Handling a Promise:
// Handling the Promise
myPromise
.then((result) => {
// This block is executed if the Promise is resolved
console.log("Success:", result);
})
.catch((reason) => {
// This block is executed if the Promise is rejected
console.error("Error:", reason);
});
Chaining Promises:
// Chaining Promises
let anotherPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("Second operation completed successfully!");
}, 2000);
});
myPromise
.then((result) => {
console.log("First Promise:", result);
return anotherPromise; // Returning a new Promise for chaining
})
.then((result) => {
console.log("Second Promise:", result);
})
.catch((reason) => {
console.error("Error:", reason);
});
Explanation:
3. Promise Creation: You create a Promise using the new Promise syntax.
Inside the Promise constructor, you perform some asynchronous operation,
and based on its result, you call either resolve (if successful) or reject (if
there's an error).
4. Promise Handling: You handle the result of a Promise using the .then()
method. If the Promise is resolved, the code inside the then block is executed.
If there's an error (Promise rejected), the code inside the .catch() block is
executed.
5. Chaining Promises: You can chain multiple Promises using the .then()
method. This is useful when you have sequential asynchronous operations.
Async/Await
Let's first look at a simple asynchronous code example without using async/await:
Explanation:
0. async Function:
The async keyword is used before a function declaration to indicate
that the function will work with promises and will implicitly return a
promise.
1. await Keyword:
Inside an async function, the await keyword is used to pause the
execution of the function until the promise is resolved. It's like saying,
"Wait for this promise to settle, and then continue."
2. Error Handling with try and catch:
We use try and catch to handle errors. If a promise is rejected, it will
throw an error, and we can catch and handle it in the catch block.
3. Simplified Code:
Using async/await makes the code more straightforward and
resembles synchronous code, making it easier to understand, especially
when dealing with multiple asynchronous operations.
Weather Website
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Air Quality Checker</title>
<style>
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
margin: 0;
background-color: #87CEEB; /* Sky Blue */
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-
serif;
}
h1 {
text-align: center;
color: #fff; /* White */
margin-bottom: 20px;
}
#input-container {
text-align: center;
margin-top: 20px;
}
label {
display: block;
margin-bottom: 5px;
color: #fff; /* White */
}
input {
padding: 10px;
margin-bottom: 15px;
width: 200px;
border: 1px solid #fff; /* White */
border-radius: 5px;
font-size: 16px;
box-sizing: border-box;
}
button {
padding: 12px 20px;
background-color: #4CAF50; /* Green */
color: #fff; /* White */
border: none;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.info {
text-align: center;
background-color: #fff; /* White */
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); /* Soft Box
Shadow */
margin-top: 20px;
display: none;
flex-direction: column;
}
.info-title {
color: #333; /* Dark Gray */
margin-bottom: 20px;
}
.info-data {
margin: 8px 0;
color: #555; /* Medium Gray */
font-size: 20px;
}
</style>
</head>
<body>
<div id="input-container">
<form id="form">
<label for="latitude">Latitude:</label>
<input type="text" id="latitude" placeholder="Enter
Latitude">
<label for="longitude">Longitude:</label>
<input type="text" id="longitude" placeholder="Enter
Longitude">
<br>
<script src="index.js">
</script>
</body>
</html>
index.js:
form.addEventListener("submit",(event)=>{
event.preventDefault();
const latitude = latitudeInput.value;
const longitude = longitudeInput.value;
const url = `https://air-
quality.p.rapidapi.com/history/airquality?lon=${longitude}&lat=${lati
tude}`;
const options = {
method: 'GET',
headers: {
'X-RapidAPI-Key': 'Key here',
'X-RapidAPI-Host': 'Host here'
}
};
fetch(url,options)
.then(response=>response.json())
.then(result=>{
let readings = result.data[0];
console.log(readings);
aqiResult.textContent=readings.aqi;
coResult.textContent=readings.co;
no2Result.textContent=readings.no2;
pm2Result.textContent=readings.pm2;
o3Result.textContent=readings.o3;
pm10Result.textContent=readings.pm10;
so2Result.textContent=readings.so2;
resultContainer.style.display = 'flex';
})
});
NodeJS Introduction
Node.js:
Node.js is a JavaScript runtime built on the V8 JavaScript engine. It allows you to run
JavaScript on the server side, enabling the development of scalable and high-
performance web applications. Node.js comes with a package manager called npm
(Node Package Manager) that allows you to easily install and manage third-party
libraries.
Node.js Installation:
Now, you have Node.js and npm installed on your system, and you can start
developing JavaScript applications. If you encounter any issues during installation,
refer to the official documentation or community forums for assistance.
The Node REPL is an interactive shell that allows you to run JavaScript code line by
line. It's a great tool for testing code snippets and exploring JavaScript features.
To launch the Node REPL, open your terminal and type node. You'll see a prompt (>)
where you can enter JavaScript code.
// Node REPL
> let greeting = 'Hello, Node.js!';
undefined
> console.log(greeting);
Hello, Node.js!
undefined
Node.js also provides a command-line interface that allows you to run JavaScript files
from the terminal. You can create and execute JavaScript files using the node
command.
Basic Code Snippet (in a file, e.g., app.js):
// app.js
const greeting = 'Hello, Node.js!';
console.log(greeting);
$ node app.js
Hello, Node.js!
Exploring NodeJS
Node.js comes with a set of built-in modules that provide various functionalities. Here
are explanations for a few of them with code snippets:
o The fs module provides an API for interacting with the file system.
const fs = require('fs');
o The http module allows you to create HTTP servers and make HTTP
requests.
const http = require('http');
o The path module provides utilities for working with file and directory paths.
// Joining paths
const fullPath = path.join(__dirname, 'files', 'example.txt');
console.log('Full Path:', fullPath);
npm is the package manager for Node.js. It allows you to easily manage and install
third-party libraries and tools for your Node.js projects.
1. Initializing a Project:
npm init
2. Installing Packages:
npm ls
4. Running Scripts:
"scripts": {
"start": "node app.js",
"test": "mocha"
}
5. Updating Packages:
6. Uninstalling Packages:
o To uninstall a package:
These are just a few examples, and there are many more npm commands and use
cases. npm is a powerful tool for managing dependencies and scripts in your Node.js
projects. For more details, refer to the official npm documentation.
date-fns Package
date-fns:
date-fns is a popular JavaScript library for working with dates. It provides a set of
functions that are designed to be simple and consistent for parsing, formatting, and
manipulating dates. Here's an overview of some of the key features of date-fns
along with code examples:
Installation:
First, you need to install the date-fns package. You can do this using npm:
Basic Usage:
Note:
o date-fns uses a functional approach and provides pure functions that do not
modify the original date objects.
o The library is modular, so you can import only the functions you need to keep
the bundle size smaller.
o It works both in the browser and in Node.js environments.
This is just a brief introduction to some of the features of date-fns. The library offers
a wide range of functions for various date-related operations. For detailed information
and additional functions, refer to the official documentation: date-fns Documentation.
ExpressJS Introduction
Express.js Introduction:
Express.js is a minimal and flexible Node.js web application framework that provides
a robust set of features to develop web and mobile applications. It simplifies the
process of building scalable and maintainable web applications by providing a fast,
unopinionated, and minimalist framework.
Installation:
Before using Express.js, you need to have Node.js installed on your system. Once
Node.js is installed, you can create a new project and install Express using npm (Node
Package Manager):
mkdir my-express-app
cd my-express-app
npm init -y
npm install express
Basic Example:
Let's create a simple Express.js application that responds with "Hello, Express!" when
you access the root URL.
node app.js
Visit http://localhost:3000 in your browser, and you should see "Hello, Express!".
Nodemon:
nodemon is a utility for Node.js that monitors for changes in your source code and
automatically restarts your server when changes are detected. This is particularly
useful during development, as it saves you from manually stopping and restarting
your server every time you make changes to your code.
Here are some key points and usage notes for nodemon:
nodemon your_script.js
Curl:
Client URL (cURL) lets you exchange data between your device and a server
through a command-line interface (CLI).
app.listen(port, () => {
console.log(`Server is running on <http://localhost>:${port}`);
});
app.listen(port, () => {
console.log(`Server is running on <http://localhost>:${port}`);
});
In this example, the body-parser middleware is used to parse JSON requests. The
data sent in the POST request is accessible through req.body.
Test Code:
You can extract parameters from the URL using :paramName in the route definition.
app.listen(port, () => {
console.log(`Server is running on <http://localhost>:${port}`);
});
Test Code:
curl <http://localhost:3000/users/123>
app.listen(port, () => {
console.log(`Server is running on <http://localhost>:${port}`);
});
Test Code:
curl "<http://localhost:3000/search?q=your_search_term>"
You can perform redirects and set specific HTTP status codes in your route handlers.
app.listen(port, () => {
console.log(`Server is running on <http://localhost>:${port}`);
});
Express provides a robust and flexible framework for handling various aspects of
HTTP requests. As your application grows, you may explore more advanced features
like route parameters, query parameters, and middleware to build powerful and
scalable APIs or web applications.
Test Code:
curl -L <http://localhost:3000/redirect>
curl -I <http://localhost:3000/notfound>
Congrats Mowa Successful ga complete chesnav! Next session lo
kaluddam :)
Middleware:
const express = require('express');
const app = express();
// Middleware function 1
app.use((req, res, next) => {
console.log('Middleware 1 executed');
// Modify the request or response objects if needed
req.customProperty = 'Hello from middleware 1';
next(); // Pass control to the next middleware
});
// Middleware function 2
app.use((req, res, next) => {
console.log('Middleware 2 executed');
// Access the modified request object from previous middleware
console.log(req.customProperty);
next(); // Pass control to the next middleware
});
// Route handler
app.get('/', (req, res) => {
res.send('Hello, Express!');
});
app.listen(3000, () => {
console.log('Server is running on port 3000');
});
Authentication:
const express = require('express');
const bodyParser = require('body-parser');
const bcrypt = require('bcrypt');
const jwt = require('jsonwebtoken');
// Routes
app.get('/', (req, res) => {
res.send('Welcome to the authentication app!');
});
app.post('/login', (req, res) => {
const { username, password } = req.body;
if (existingUser) {
res.status(400).json({ message: 'Username already exists. Choose
another one.' });
} else {
// Hash the password before storing (using bcrypt)
const hashedPassword = bcrypt.hashSync(password, 10);
// Protected route
app.get('/protected', verifyToken, (req, res) => {
res.json({ message: 'You have access to this protected route!' });
});
if (!token) {
return res.status(403).json({ message: 'No token provided.' });
}
req.user = decoded;
next();
});
}
app.listen(PORT, () => {
console.log(`Server is running on <http://localhost>:${PORT}`);
});
ReactJS in 46 Min
Introduction to React JS
o JavaScript library for building user interfaces: React is a powerful tool for
creating dynamic and interactive web applications. It focuses on building
reusable components that manage their own state and render efficiently.
o Declarative approach: You describe the desired UI state, and React handles
the updates efficiently, making it easier to reason about and maintain your
code.
o JSX syntax: React uses a syntax extension for JavaScript called JSX, which
allows you to write HTML-like structures within your JavaScript code.
o Virtual DOM: React maintains a virtual representation of the UI in
memory, which it compares to the previous version to determine the minimal
changes needed for updates. This makes updates fast and efficient.
Basic Concepts:
<!DOCTYPE html>
<html>
<head>
<title>Hello React</title>
<script
src="<https://unpkg.com/react@18/umd/react.development.js>"
crossorigin></script><script
src="<https://unpkg.com/react-dom@18/umd/react-dom.development.js>"
crossorigin></script></head><body><div
id="root"></div><script
src="script.js"></script></body></html>
2. Create a JavaScript file (script.js):
Explanation:
o Import React and ReactDOM: These libraries are necessary for working
with React.
o Create a root element: The createRoot method attaches React to a DOM
element (#root).
o Render a component: The root.render method renders a React
component, in this case, an <h1> element with the text "Hello, world!".
Notes:
o JSX syntax: Note the use of JSX to write HTML-like code within JavaScript.
o Development vs. production: The included script URLs are for development
purposes. For production, use optimized builds.
o Setting up React projects: For larger projects, consider using tools like
Create React App to streamline setup and development.
Key Points:
1. Prerequisites:
o Node.js (version 14 or later) and npm (or yarn) installed on your system.
2. Installing React:
o public: Contains static assets like images, favicons, and the index.html file.
o src: Holds the source code of your React application.
App.js: The main component, usually the entry point.
index.js: Renders App component into the root DOM element.
components: Stores reusable React components.
styles: Houses CSS or stylesheet files.
assets: Holds additional static assets (images, fonts, etc.).
o package.json: Lists project dependencies and scripts for development and
building.
Key Concepts:
Components
Types:
function App() {
const userName = 'John';
return (
<div>
<Greeting name={userName} />
</div>
);
}
handleClick = () => {
this.setState({ count: this.state.count + 1 });
};
render() {
return (
<div><p>You clicked {this.state.count} times</p><button
onClick={this.handleClick}>Click me</button></div>
);
}
}
Props
Key Points:
Example:
// Usage:
<WelcomeMessage title="Welcome to React" message="Let's get started!"
/>
Additional Notes:
o Use defaultProps to set default values for props when not provided.
o Use PropTypes for type checking and validation of props.
o Props are immutable within child components; use state for internal data
management.
Conditional Rendering
render() {
if (this.state.isLoggedIn) {
return (
<div>
<p>Welcome, User!</p>
</div>
);
} else {
return (
<div>
<p>Please log in</p>
</div>
);
}
}
}
render() {
let content;
if (this.state.isLoggedIn) {
content = <p>Welcome, User!</p>;
} else {
content = <p>Please log in</p>;
}
return <div>{content}</div>;
}
}
render() {
return (
<div>
{this.state.isLoggedIn ? (
<p>Welcome, User!</p>
) : (
<p>Please log in</p>
)}
</div>
);
}
}
render() {
return (
<div>
{this.state.isLoggedIn && <p>Welcome, User!</p>}
{!this.state.isLoggedIn && <p>Please log in</p>}
</div>
);
}
}
render() {
return (
<div>
<h1>Conditional Rendering Example</h1>
{this.state.isLoggedIn ? (
<div>
<p>Welcome, User!</p>
<button onClick={this.toggleLoginStatus}>Logout</button>
</div>
) : (
<div>
<p>Please log in</p>
<button onClick={this.toggleLoginStatus}>Login</button>
</div>
)}
</div>
);
}
}
In this example:
o The component has a state variable isLoggedIn to track whether the user is
logged in or not.
o The toggleLoginStatus function is responsible for toggling the isLoggedIn
state.
o The render method contains conditional statements that check the
isLoggedIn state. Depending on the state, it renders different content.
The buttons allow the user to toggle the login status, triggering a re-render with the
updated state and, consequently, conditional rendering.
Styled Components is a popular library for styling React components using tagged
template literals. It allows you to write CSS in JavaScript, keeping styles encapsulated
within your components. Here's a brief explanation with example code snippets:
87. Installation: First, install the Styled Components library in your React
project:
88. npm install styled-components
89.
90. Usage: Import styled from the styled-components library, and use it to
create styled components.
91. // ExampleComponent.js
92.
93. import styled from 'styled-components';
94.
95. // Create a styled component
96. const StyledDiv = styled.div`
97. background-color: lightblue;
98. padding: 10px;
99. margin: 10px;
100. `;
101.
102. // Use the styled component in your React component
103. const ExampleComponent = () => {
104. return (
105. <StyledDiv>
106. <h1>Hello, Styled Components!</h1>
107. </StyledDiv>
108. );
109. };
110.
111. export default ExampleComponent;
112.
136. Global Styles: Styled Components also allows you to define global
styles using the createGlobalStyle utility.
137. // GlobalStyles.js
138.
139. import { createGlobalStyle } from 'styled-components';
140.
141. // Define global styles
142. const GlobalStyles = createGlobalStyle`
143. body {
144. font-family: 'Arial', sans-serif;
145. background-color: #f0f0f0;
146. }
147. `;
148.
149. export default GlobalStyles;
150.
Import the GlobalStyles component in your main file (e.g., App.js) to apply
global styles to your entire application.
// App.js
In this example, the GlobalStyles component sets global styles for the body
element.
MongoDB
Introduction to MongoDB:
Types of Databases:
Non-Relational Databases:
Why MongoDB:
MongoDB offers several advantages that make it a popular choice for developers and
organizations:
Installation (Windows):
Prerequisites:
Installation Steps:
Verification:
o Open a new command prompt window (search for "cmd" in the Start menu).
o Type mongosh and press Enter.
If the installation was successful, you should see the mongosh shell prompt:
connecting to mongodb://127.0.0.1:27017/test Welcome to the MongoDB
shell MongoDB shell version v<version> ...
Additional Notes:
o If you encounter any issues during installation, refer to the official MongoDB
documentation for troubleshooting
steps: https://www.mongodb.com/docs/mongodb-shell/install/
o You can now use mongosh to connect to your local MongoDB instance (if
installed) or connect to remote MongoDB deployments.
Installation (macOS):
Homebrew is a popular package manager for macOS that simplifies installing and
managing software.
Bash
brew update
Bash
Install MongoDB:
Bash
Bash
Bash
Additional Notes:
o Consider using the Homebrew method for easier updates and management.
o The official MongoDB documentation provides more
details: https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-
os-x/
Installation (Ubuntu):
Prerequisites:
Installation Steps:
Bash
Bash
Bash
Bash
Verification:
Additional Notes:
o This guide installs the shell only. To install the full MongoDB server for local
database management, follow the official MongoDB documentation for
Ubuntu: https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-
ubuntu/
o Consider using a version control system like apt to manage package updates
for security and stability.
1. Create (Insert):
2. Read (Query):
o Find Documents:
o db.collection.find({ age: { $gt: 25 } }); // Find documents
where age is greater than 25
o
o Projection:
o db.collection.find({}, { name: 1, age: 1 }); // Include only
name and age fields
o
3. Update:
4. Delete:
Conditional Operators:
Example:
Example:
Ordering Results:
MongoDB allows sorting query results based on one or more fields in ascending or
descending order.
Example:
Example:
Logical Operators:
o $and:
o $or:
o $not:
Aggregation:
In MongoDB, the aggregation framework provides powerful tools for performing data
transformations and computations on the documents within a collection. It allows you
to process and analyze data, including grouping, filtering, sorting, and performing
various calculations. Let's delve into the details:
Aggregation Stages:
The aggregation framework consists of various stages, each performing a specific
operation on the input documents and passing the results to the next stage. Some
common stages include:
Aggregation Operators:
Aggregation Example:
[
{ "name": "Nihar", "score": 85, "grade": "3rd year", "course":
"Artificial Intelligence and Machine Learning" },
{ "name": "Yuktha", "score": 78, "grade": "2nd year", "course":
"Artificial Intelligence and Machine Learning" },
{ "name": "Maheshwar", "score": 92, "grade": "2nd year", "course":
"Chemistry" },
{ "name": "Vignesh", "score": 88, "grade": "2nd year", "course":
"Biology" },
{ "name": "Naman", "score": 79, "grade": "1st year", "course":
"Computer Science" },
{ "name": "Varun", "score": 90, "grade": "2nd year", "course":
"English" },
{ "name": "Shreya", "score": 84, "grade": "1st year", "course":
"History" },
{ "name": "Naveen", "score": 86, "grade": "1st year", "course":
"Economics" }
]
$match: Filters documents to pass only the documents that match the specified
condition.
db.aggregation.aggregate([
{ $match: { grade: "1st year" } }
])
This query will return only the documents where the grade is "1st year".
db.aggregation.aggregate([
{ $group: { _id: "$grade", averageScore: { $avg: "$score" } } }
])
This query will group documents by the "grade" field and calculate the average score
for each group.
db.aggregation.aggregate([
{ $sort: { score: -1 } }
])
This query will sort the documents in descending order based on the "score" field.
db.aggregation.aggregate([
{ $project: { name: 1, grade: 1, course: 1 } }
])
This query will include only the "name", "grade", and "course" fields in the output.
$count: Returns a count of the number of documents at this stage of the aggregation
pipeline.
db.aggregation.aggregate([
{ $count: "totalStudents" }
])
This query will return the total count of documents in the collection.
These are just a few examples of aggregate functions in MongoDB. They allow for
powerful data manipulation and analysis within the database itself.
Congrats Mowa Successful ga complete chesnav! Next session lo
kaluddam :)
We’ll be building actual websites very soon by making use of the concepts
learnt till now. Stay tuned :)