OCR A Level Computer Science: 3.4 Web Technologies
OCR A Level Computer Science: 3.4 Web Technologies
Page 1 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Crawling
Web pages are discovered by search engines through software programs called crawlers (or spiders,
bots, or robots)
Crawlers follow links from one webpage to another, systematically visiting pages on the web
They start from a set of seed URLs and visit other pages linked from those URLs
Website crawlers follow rules and guidelines established by website owners, using mechanisms like
the robots.txt file. These guidelines direct crawlers on which areas of a website to explore or avoid,
respecting website preferences and ensuring privacy
Once a crawler reaches a webpage, it fetches the HTML content of that page
The crawler examines the HTML structure and retrieves information, such as text content, headings,
links, and metadata
To understand the structure of the webpage, the HTML that was retrieved is broken down into
individual components
This process involves identifying elements, tags, and attributes that hold valuable information like
titles and headings
Indexing
The data extracted from the webpage is indexed, which involves storing the collected information in a
structured manner within a search engine's database
Page 2 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Each word in the document is included in the page's index as an entry, along with the word’s position
on the page
Your notes
The index allows for quick retrieval and ranking of relevant web pages in response to user queries
Ranking
When a user enters a query, the search engine searches the index for matching pages and returns the
results they believe are the highest quality and most relevant to the user's query
Efficient retrieval
Indexing enables efficient retrieval of information
Search engines don't need to scan the entire web for every search query. They can just search their
indexed data to produce search results quickly
Page 3 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Search result rankings are determined by various ranking algorithms that analyse indexed data. These
algorithms consider factors such as keyword relevance, backlinks, and user engagement
Freshness & updates Your notes
Search engine crawlers periodically revisit indexed web pages to detect updates and changes
This process guarantees that the search results display the latest content that is currently accessible
on the Internet
If a webpage has been updated and not re-crawled, the page may no longer be relevant for the user's
search
Page 4 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
PageRank Algorithm
Your notes
PageRank Algorithm
A crucial element of search ranking algorithms is the Page Rank algorithm
The algorithm was developed by Larry Page and Sergey Brin
Many search engines rely on it, particularly Google
Web pages are evaluated and ranked by the algorithm based on their perceived relevance and
importance
Link analysis
The PageRank algorithm analyses the structure of links between pages on the web
Web pages are given importance by the algorithm, which considers the quantity and quality of
inbound links from other pages
Each link acts as a "vote" for the target page, with the voting weight determined by the importance of
the linking page
Websites that have more high-quality links pointing towards them are deemed to be more valuable
and pertinent and have a higher weight
Page 5 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Webpages with a higher weight will score more highly and have a higher ranking
Link weight distribution
Your notes
The importance of a webpage is calculated by PageRank, which takes into account the total number
of "votes" it has received
The algorithm distributes the importance of a page to the pages it links to by sharing a portion of its
importance with each outgoing link
By following this process, pages of superior quality are given greater importance and make a larger
impact in determining the ranking of other pages
Iterative calculation
The PageRank algorithm uses a repetitive calculation process. At the beginning, every webpage is
given the same value to start with
In subsequent iterations, the significance of each page is re-evaluated by considering the weighted
impact of inbound links
The process continues until the rankings become stable
Damping factor
In order to avoid infinite loops, an algorithm introduces a damping factor that ranges between 0 and 1
(usually set at 0.85)
The damping factor is the likelihood of a user clicking on a link at random rather than following the links
on the current page
The damping factor ensures that the ranking calculation includes user behaviour and maintains
harmony between discovering new links and staying on the current page
Page 6 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Relevance
The content of a web page is a crucial factor in determining its ranking in search results. This is Your notes
influenced by the keywords used, the quality of the content, and how relevant it is to the search query
User engagement
The way users interact with a website can be measured through metrics like click-through rates, time
spent on a page (dwell time), and bounce rates. These metrics can reveal the level of user engagement
Pages that receive greater engagement from users may be deemed more valuable
Content freshness
Search engines value fresh and up-to-date content
Search queries may give priority to web pages that are frequently updated or have up-to-date
information
Mobile-friendliness
As mobile devices became more prominent, search engines started to factor in the mobile
compatibility of web pages when determining their ranking
Google primarily uses the mobile version of a site's content to rank pages from that site
Having a responsive design and optimising the user experience on mobile devices can have a
positive impact on a website's rankings
Page 7 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Page 8 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Your notes
PageRank Analogy - the players receive a numerical rating based on number and frequency of passes
As more passes are made, the PageRank of each player undergoes changes
As a result, the PageRank of every player they pass to will be altered
The number represents each player's PageRank - the higher the number, the better
Once the game concludes, players can be ranked to determine the best performer
Page 9 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Your notes
EXAM TIP
In the exam, you won't be asked about the algorithm specifically, just the overall idea of how it
works, as detailed above
You don't need to know exactly how it is calculated
Although it was created by Google, it's used by many search engines so don't mention Google
in the exam
Page 10 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Server operations
PHP can perform server side operations that are not accessible to the client
PHP is capable of performing server operations such as retrieving and displaying information from a
database
Form processing
PHP can handle form submissions, process the submitted data, and perform necessary validations or
database operations on the server side
Improved security measures can be implemented When multiple requests are made to a server,
through server side processing, ensuring the secure complex processing tasks can consume server
Page 11 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
management of sensitive data, implementing resources and cause a decrease in overall server
access control measures, and guarding against performance. This is known as increased server
common web vulnerabilities. load. Your notes
Server side processing uses the resources of the Using server side processing may cause latency
server to perform advanced calculations, manipulate because it involves communication with the
data, and interact with databases. server, which could lead to slower response
times in comparison to client side processing.
Server side processing ensures consistent Server side processing relies on the availability
behaviour across different devices and browsers, and reliability of the server infrastructure.
as the processing logic is centralised on the server. Downtime or performance issues can affect the
functioning of the web application.
Server side processing can be easily scaled by Server side processing typically requires a
adding more servers or optimising the server roundtrip to the server for each user action,
infrastructure to handle increasing traffic and user limiting real-time interactivity and
demands. responsiveness.
Page 12 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Form validation
With JavaScript, it's possible to validate user input in real time, which means that users can receive Your notes
instant feedback without the need for a server roundtrip
E.g. when completing an online form, check that all required fields are filled out correctly and make
sure the input meets the necessary format and length before sending the form to the server. If any
areas are blank and need input (e.g. email address) the user will be notified before the form can be
submitted
DOM manipulation
With JavaScript, developers can modify the Document Object Model (DOM) to make dynamic
changes to a web page's content and structure
This involves tasks such as adding or removing elements, updating text, modifying styles, and
managing events to develop interactive user interfaces e.g. turning on dark mode
AJAX requests
Communication with the server happens asynchronously and retrieves data in the background
This allows for dynamically updating content without requiring a full-page reload
Enhanced user experience is made possible through There is a potential security risk with client side
client side processing, creating interactive and code as it can be seen by users, which may lead
dynamic user experiences. This eliminates the need to sensitive information and operations being
for frequent server requests and page reloads. exposed or tampered with.
By offloading processing tasks to the client side, the The compatibility of devices and browsers may
server load is reduced, resulting in improved vary, which can lead to issues with the client side
scalability and resource utilisation. code that depends on their capabilities and
support.
User input can be instantly validated and feedback Client side processing can hurt page load time,
can be provided in real-time. This not only improves particularly when dealing with large or complex
Page 13 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
the user experience but also reduces the need for operations that require substantial processing
server roundtrips. power.
Your notes
With the use of JavaScript, web pages can have their Client side processing is heavily dependent on
content updated dynamically, resulting in a more JavaScript. If the user's browser does not
seamless and engaging browsing experience. support or has disabled JavaScript, the
functionality may become inaccessible or
break.
Web applications can operate without an active The accessibility of client side code to users can
internet connection by using client side technologies put intellectual property at risk, as it allows for
to provide offline functionality. easier viewing, copying, and modification of the
code.
WORKED EXAMPLE
Big Brains has produced a website that allows students to access revision videos. They want to
limit access to those students with a school email account (i.e. one ending .sch.uk). When
students sign up JavaScript is used to check that the email address they have entered is from a
school account. The address is rechecked when it reaches the server before login details are sent
to the address.
Explain why checking the email address with JavaScript and again when it reaches the server is
important.
3 marks
How to answer this question:
Page 14 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
You need to know the following from above about client side processing:
Reduced Server Load: Offloading processing tasks to the client side reduces the burden Your notes
on servers, improving scalability and resource utilisation
Dependency on JavaScript: Client side processing heavily relies on JavaScript, and if
JavaScript is disabled or not supported by the user's browser, the functionality may break or
become inaccessible
You need to apply this knowledge to the scenario in the question
Answer:
Example answer that gets full marks:
The JavaScript check is carried out client side meaning the address can be checked and stopped
before reaching the server reducing the unnecessary load on the server.
Acceptable answers you could have given instead:
JavaScript can be amended and circumvented therefore address must be checked at the server to
ensure this has not happened.
Page 15 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
HTML
Your notes
Writing HTML
HTML, or HyperText Markup Language, is the foundational language used to structure content on the
web
HTML consists of a series of elements, often referred to as "tags," which can be used to structure and
format a webpage
The <html> tag is the root element of an HTML page. The tag includes all other HTML elements used on
the page
Most tags are opened and closed e.g. <html> and </html> whereas some tags are only opened e.g.
<img> and <link>
The content layer of a web page is made up of HTML elements such as headings (<h1>, <h2>, etc.),
paragraphs (<p>), links (<a>), images (<img>), and more
EXAM TIP
An exam question which asks you to write HTML is asking you to write code which is specifically
HTML. This means all spelling and syntax MUST be correct for you to get the marks
The Head
The head section contains information about the web page that's not displayed on the page itself
The head section is enclosed by <head> and </head> Tags
Some of the content inside the head tag is shown in the browser tab
Page title
The <title> element is used to set the page title that shows in the browser tab
The crown is placed inside the <head> section of the HTML document
E.g. <title>Sample Webpage</title>
External stylesheet
External stylesheets are linked in the <head> section using the <link> element
Page 16 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
The rel the attribute is set to "stylesheet", and the href the attribute contains the relative file path to the
CSS file
Your notes
Stylesheets are loaded in the order they are listed, so hierarchy is important
E.g. <link rel="stylesheet" type="text/css" href="styles.css">
The Body
The body section contains the main content of the web page, such as text, images, videos,
hyperlinks, tables etc.
The body section is enclosed by <body> and </body> Tags
The content inside the body tag is displayed in the browser window
Headings
Headings help users understand how a page is organised and structured. They help guide the user's
eye around the page and help them quickly find the information they're looking for
Headings are also important for users that use screen readers, such as visually-impaired users. Screen
reader software uses headings to help the user navigate around the page (e.g. providing a list of all the
headings on the page, and allowing the user to jump straight to a particular heading)
The tags used for headings are <h1>, <h2>,<h3> etc.
<h1> is the highest level heading, with <h2> and <h3> serving as subheadings
The number in the tag denotes the level of the heading. Headings should be used hierarchically, with
<h1> the most prominent, and <h6> the least prominent
Headings are also important for Search Engine Optimisation (SEO), as they help search engines like
Google understand the content and structure of the page
E.g.
<h1>Welcome to My Sample Webpage</h1>
Images
The <img> tag embeds an image into an HTML document
The img tag includes the src attribute which specifies the URL of the image (the source of the attribute),
and the alt attribute which provides alternative text for screen readers or in cases where the image
cannot be displayed. The tag also helps search engines understand the content of the image
Page 17 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
The height and width attributes specify the dimensions of the image
E.g. <img src="https://cdn.savemyexams.com/logo/sme-logo-small.svg" alt="Save My Exams Image" height="100" Your notes
width="200">
Links
The <a> tag, or anchor tag, is used to create hyperlinks
The tag includes the href attribute which specifies the URL that the link points to
This can be included within another tag to specify the text which will be displayed
E.g. <p>Visit the <a href="https://www.savemyexams.co.uk">Save My Exams site</a> for more information.</p>
An image can also become a hyperlink
E.g. <a href=”https://www.savemyexams.co.uk”><img src=”logo.png”></a>
Div
The <div> tag is a generic container that can be used to group other HTML elements together
The div tag is often used in conjunction with CSS to style sections of a webpage
Form
The <form> tag is used to create a form for user input
Input
The <input> tag is used within a <form> tag to create interactive controls for web-based forms
The type attribute can be set to "text" to create a textbox, or "submit" to create a submit button
The name attribute is used to identify the input
E.g.
<form action="/submit" method="post">
<label for="age">Age:</label>
<label for="email">Email:</label>
Page 18 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
</form>
Lists
The <li> tag is used to define a list item
The <ol> and <ul> Tags are used to create ordered and unordered lists
An ordered list will look like numbered bullet points
An unordered list will look like normal bullet points
<li> tags are nested within these to show each item in the list
E.g.
<ul>
<li>html</li>
<li>head</li>
<li>title</li>
<li>body</li>
<li>p</li>
<li>a</li>
<li>img</li>
<li>div</li>
<li>form</li>
<li>input</li>
<li>script</li>
</ul>
Page 19 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
JavaScript
The <script> tag is used to embed or reference JavaScript code within an HTML document Your notes
E.g. <script src="script.js"></script>
EXAM TIP
It's important to note that the correct usage of relative paths/URLs depends on the file structure
and organisation of your web project. Carefully consider the relative relationship between files
and directories to ensure accurate referencing of resources
<div id="header">
<h1>Study Guide</h1>
</div>
<h2>Maths Revision</h2>
</div>
<h2>English Revision</h2>
Page 20 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
</div>
</div>
</body>
Styling is covered in more detail in CSS but here’s an example to illustrate the use of classes and IDs:
/* styles.css */
#header {
background-color: lightblue;
padding: 10px;
text-align: center;
.subject {
margin: 10px;
padding: 10px;
#maths {
background-color: #FFDDDD;
#english {
background-color: #DDFFDD;
#science {
Page 21 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
background-color: #DDDDFF;
} Your notes
<html>
Page 22 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
<head>
</head>
<body>
<p>This is a sample webpage created to demonstrate the usage of various HTML tags.</p>
<ul>
<li>html</li>
<li>head</li>
<li>title</li>
<li>body</li>
<li>p</li>
<li>a</li>
<li>img</li>
<li>div</li>
<li>form</li>
<li>input</li>
<li>script</li>
</ul>
<h2>Contact Us</h2>
Page 23 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
<div>
</div>
<div>
</div>
</form>
<h3>Image Example</h3>
<h3>External Link</h3>
</body>
<script src="script.js"></script>
</html>
WORKED EXAMPLE
One page in the website contains a hyperlink on an image. When the image stored as
“ticket.png” is clicked, the user is hyperlinked to the page stored as “booking.htm”.
Write the HTML code to implement this hyperlink.
3 marks
How to answer this question:
You can use the example code from above to write the link:
<a href=”https://www.savemyexams.co.uk”><img src=”logo.png”></a>
You’ll need to change the link to the one given in the question (booking.htm) and change the image
name to the one given in the question too (ticket.png)
Page 24 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
EXAM TIP
When you’re given a link or filename in the question, make sure you copy it exactly as it appears.
Your case (capital letters) and spelling need to be spot on to make sure you don’t drop marks!
E.g. https://www.youtube.com/watch?v=fQBfpaiYlWg is not the same as
https://www.youtube.com/watch?v=fqbfpaiyiwg
Page 25 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
CSS
Your notes
Writing CSS
Cascading Style Sheets (CSS) define the style or appearance of a webpage
CSS uses selectors such as classes or IDs
CSS can be placed within HTML or externally in a file
Multiple pieces of CSS can be combined
Where CSS is used within the HTML, this will be used rather than any external CSS styling and will
override the external stylesheet
Identifiers
An identifier, also known as an ID, is another type of selector in CSS
An identifier is represented by a hash (#) followed by the ID name. For example, #myID would select
any HTML element with the ID attribute set to "myID"
IDs are unique within a webpage, meaning that each ID can only be used once per page. This makes
them useful for styling singular, distinct elements on a webpage
E.g.
<body>
<div id="header">
<h1>Study Guide</h1>
Page 26 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
</div>
</div>
<h2>English Revision</h2>
</div>
<h2>Science Revision</h2>
</div>
</body>
#header {
background-color: lightblue;
padding: 10px;
text-align: center;
.subject {
margin: 10px;
padding: 10px;
Page 27 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
#english {
background-color: #DDFFDD;
#science {
background-color: #DDDDFF;
Page 28 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Your notes
All the subjects have the same border and heading style but each one has a different coloured
background
Page 29 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
CSS: Styling
Your notes
Writing CSS: Styling
CSS can be used to style individual elements e.g. all of the h1s or all the paragraphs
h1{
color:blue;
CSS can also be used to style classes by adding a . before the class name
.infoBox{
background-color: green;
background-color: #A2441B;
Styling can also be done inline (in the HTML). The examples below will cover both
<p style="background-color: lightblue;”> Save My Exams </p>
background-color: lightblue;
padding: 10px;
text-align: center;
EXAM TIP
Page 30 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Your code must be exactly what it appears on this page. So color must be spelt the American
way as colour doesn’t work in CSS. Make sure you know the properties listed below and don’t
name them something which is incorrect e.g. text-colour instead of color Your notes
Also make sure your syntax is correct so use : instead of =
Properties
background-color
Example within HTML
<p style="background-color: lightblue;”> Save My Exams </p>
background-color: lightblue;
border-color
Example within HTML
<p style="border-color: black; > Save My Exams </p>
border-color: black;
border-style
Example within HTML
<p style="border-style: solid; ” > Save My Exams </p>
border-style: solid;
Page 31 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
border-width
Example within HTML Your notes
<p style="border-width: 2px; ”> Save My Exams </p>
border-width: 2px;
colour
Note that this changes the font colour
Example within HTML
<p style="color: #ff0000; ”> Save My Exams </p>
color: #ff0000;
font-family
Example within HTML
<p style="font-family: Arial;” > Save My Exams </p>
font-family: Arial;
font-size
Example within HTML
<p style="font-size: 14px; ” > Save My Exams </p>
Page 32 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
height: 200px;
width: 200px;
Colours
Colours can be referred to by name or hex number
Colour is spelt the American way in CSS (color) - the code won't work if written the British way (colour)
There are 140 colour names which can be used. Here is a selection:
Page 33 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Blue is #0000FF
A colour picker can be used to get the hex code for a particular colour Your notes
WORKED EXAMPLE
The site also contains the following code.
<div class="offer">All oranges 50% off.</div>
Complete the CSS code that would make any div elements of the class offer have an orange
border.
2 marks
..........{
border-style: solid;
..........
border-style: solid;
border-color: orange;
Page 34 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
JavaScript
Your notes
JavaScript
What is JavaScript?
JavaScript is a programming language that adds interactivity and dynamic functionality to webpages. It
allows a webpage to manipulate HTML elements, perform calculations, handle user input, and more.
Purpose of JavaScript
JavaScript is primarily used for client-side scripting, meaning it runs directly in the web browser of the
user
Its purpose is to enhance webpages by enabling interactive features, dynamic content, form
validation, and data manipulation
Interactive features include features like image sliders, drop-down menus, or interactive maps,
like allowing users to zoom in and out on a Google Maps element embedded in the website
Dynamic content could be loading more articles or posts when a user reaches the end of a page
(infinite scrolling), or changing the content based on the user's actions, such as showing different
product descriptions when a user hovers over product images
Form validation could be checking that all required fields have been filled in, that an email
address has the correct format, or that passwords meet certain strength requirements
Data manipulation could involve filtering a list of products based on user-selected criteria,
sorting a table of data, or creating a dynamic chart that updates in real-time as new data comes
in
JavaScript can respond to user actions, update the content of HTML elements, and communicate with
servers to retrieve or send data
Page 35 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Example let x = 5;
It is important to choose the correct data type for a given situation to ensure accuracy and efficiency in the
program.
Page 36 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Examples in JavaScript:
let score = 10;
const PI = 3.14;
EXAM TIP
You might see code that declares variables like this
var variableName = value;
Page 37 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
This is bad practice as it utilises global variables but was used until 2015 when let was added to
JavaScript
Your notes
Page 38 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Outputs in JavaScript
Your notes
Outputs in Javascript
There are several ways to produce outputs in JavaScript:
The first line of code uses the document.getElementById() method to retrieve the HTML element with the
ID "example" from the document's DOM (Document Object Model)
The returned element is assigned to the variable chosenElement, which allows further manipulation of
that element
The second line of code modifies the content within the chosenElement HTML element
The innerHTML property allows direct access to the HTML content within an element
In this case, the content of chosenElement is changed to "Hello World", effectively replacing any existing
content with this new text
This code writes the text "Hello World" directly to the webpage
This code triggers an alert box with the message "Hello World"
Page 39 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Your notes
Page 40 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Selection in JavaScript
Your notes
Selection in JavaScript
Programming code is made up of constructs which control the flow of a program
Constructs tell the computer the order in which to carry out the statements/lines of code
There are 3 programming constructs:
Sequence
Selection
Iteration
Selection is selecting a line/lines of code to run depending on whether a condition is true or false
There are two ways to write selection statements:
If statements
When writing a condition there will need to be a comparison operator. They are listed below:
== equal to x == 8 false
x == 5 true
x == "5" true
Page 41 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
x !== 8 true
IF Statements in JavaScript
An if the statement will let you choose a line/lines of code to run if a condition is true or false
Below are three examples of if statements:
1. if
2. if else
3. if else if else
Syntax of an if statement
The syntax of an if the statement consists of the if keyword, followed by a condition enclosed in brackets,
and a code block that is executed if the condition evaluates to true:
if (condition) {
// Code to be executed if the condition is true
}
Page 42 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Your notes
if (number > 0) {
console.log('The number is positive.');
}
In this example, the if statement checks if the value of the variable number is greater than 0. If the
condition is true, the message 'The number is positive.' is output to the browser
Page 43 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Your notes
if (number > 0) {
console.log('The number is positive.');
} else {
console.log('The number is not positive.');
}
In this example, if the value of number is greater than 0, the message 'The number is positive.' is output.
Otherwise, the message 'The number is not positive.' is output
Page 44 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
} else if (condition) {
Page 45 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
console.log('Good.');
} else if (score >= 70) {
console.log('Fair.'); Your notes
} else {
console.log('Needs improvement.');
}
In this example, the if-else if-else statement evaluates the value of score to determine the corresponding
message based on the score range
EXAM TIP
You can use as many else ifs as you want to within your if statement but it might be clearer to use a
switch case statement
You can have an if else-if statement without an end as the catch-all condition at the end
Page 46 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
WORKED EXAMPLE
A website sells tickets for sporting events. The website uses HTML, CSS and JavaScript. The
website charges a booking fee of £2.99 on each ticket sold. In addition, if the tickets are
purchased from outside of the UK, £4.99 is added to the booking fee. The booking fee is
calculated using a JavaScript function named bookingfee().
Complete the definition of the bookingfee() function below.
function bookingfee(numtickets, country) {
var nonUKprice = 4.99;
var perTicketPrice = .............................................;
var total = 0;
if (country!="UK") {
total = total + .............................................;
}
total = total + (............................................. * perTicketPrice);
return total;
}
3 marks
How to answer this question:
The first blank space is to set the value of the perTicketPrice. The question tells us this is £2.99
The 2nd blank space is to add something to total if the country is not equal to UK. The question
tells us that if the tickets are purchased from outside the UK, £4.99 is added to the booking fee.
This is stored in the nonUKprice variable
The 3rd blank space is something multiplied by perTicketPrice. The question tells us each ticket is
£2.99 so we need to multiply the perTicketPrice by the number of tickets (called numtickets)
Answer:
Example answer that gets full marks:
Page 47 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
EXAM TIP
When you're given code in a question that you need to refer to or complete, you must spell
existing identifier names exactly as they have in the question. E.g. if you write numtikets instead of
numtickets you won't get the mark
Also, make sure you don't include £ in the calculation - this will be added as an output and will
cause the calculation to not work as it's included a character that's not an integer
Page 48 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Fall-Through behaviour
By default, switch case has a fall-through behaviour, meaning that if a case label matches, the code
execution continues to the next case until a break statement is encountered. This allows you to group
multiple cases with the same code:
Page 49 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
In this example, if day is 'Tuesday', 'Weekday' is logged to the console because it falls through the cases
of 'Monday' to 'Friday' until a break statement is encountered
Page 50 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
1. Initialisation: The initialisation is executed only once at the beginning of the loop. It is used to initialise a
counter variable that controls the loop's execution
2. Condition: The condition is evaluated before each iteration. If the condition evaluates to true, the loop
continues executing the code block. If the condition evaluates to false, the loop terminates
3. Increment/Decrement: The increment or decrement statement is executed at the end of each
iteration, updating the counter variable to control the loop's progress
Page 51 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Your notes
Page 52 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Your notes
EXAM TIP
You might have seen i=i+1 or i+=1 for incrementing by 1. This is the same as i++ in JavaScript
The list fruits contains four items: 'apple', 'banana', 'orange', and 'grape'
The for...in the loop iterates over each index of the fruits list
Page 53 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
In each iteration, the index the variable is assigned the current index value
Inside the loop, we use fruits[index] to access the value associated with the current index Your notes
The loop executes the code block, which outputs the index and value of each item in the list to the
browser
Page 54 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
The condition is evaluated before each iteration. If the condition evaluates to true, the code block is
executed. If the condition evaluates to false, the loop terminates
Page 55 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Your notes
Page 56 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Your notes
Page 57 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
do {
// Code to be executed at least once
} while (condition); Your notes
Code Block: The code block is executed first before evaluating the condition
Condition: The condition is evaluated after executing the code block. If the condition evaluates to true,
the loop continues executing. If the condition evaluates to false, the loop terminates
Do while loop in JavaScript - a dice roll repeats until the target number is met
EXAM TIP
Page 58 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
You can use either a while loop or a do while loop but don't forget that a do while loop will always
run once before checking if the condition is true
Your notes
Page 59 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Strings in JavaScript
Your notes
Strings in JavaScript
A string is a sequence of characters enclosed in single quotes (') or double quotes ("). Strings are widely
used for representing and manipulating text-based data.
Creating strings
Strings can be created in JavaScript by enclosing text within quotes:
const message = 'Hello, world!';
const name = "John Doe";
String length
To find the length of a string, use the length property
The length property returns the number of characters in a string:
const message = 'Hello, world!';
console.log(message.length);
// Output: 13
In this example, the length property is used to determine the number of characters in the message string
Substring extraction
To extract a portion of a string, use the substring() method
The substring() method takes two parameters: the starting index and the ending index (optional)
A new string is returned containing the characters within the specified range:
const message = 'Hello, world!';
const substring = message.substring(0, 5);
console.log(substring);
// Output: Hello
In this example, the substring() method is used to extract the characters from index 0 to index 5
(exclusive) from the message string, resulting in the substring 'Hello'
Page 60 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
By omitting the second parameter, the substring() method will extract the characters from the starting
index to the end of the string:
const message = 'Hello, world!'; Your notes
const substring = message.substring(7);
console.log(substring);
// Output: world!
Here, the substring() method extracts the characters from index 7 to the end of the message string,
resulting in the substring 'world!'
EXAM TIP
JavaScript allows flexibility in choosing single or double quotes to define strings, as long as you
maintain consistency within a string
There are many other things you can do with strings in JavaScript but these are the only ones you
need to know before the exam
The exam might give you additional string functionality but if it does it will provide the code and
explain it
Page 61 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Operators in JavaScript
Your notes
Arithmetic Operators in JavaScript
Arithmetic operators are symbols or keywords used to perform mathematical calculations and operations
on numerical values. They allow the computer to perform addition, subtraction, multiplication, division,
and more.
In this example, the addition operator adds the values 5 and 3, resulting in 8
It also concatenates the strings 'John', ' ', and 'Doe' to form the full name 'John Doe'
In this example, the subtraction operator subtracts the value 4 from 10, resulting in 6
In this example, the multiplication operator multiplies the values 3 and 5, resulting in 15
In this example, the exponentiation operator multiplies the value 3 to the power 3, resulting in 27
Page 62 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
The division operator (/) is used to divide one numerical value by another:
const quotient = 10 / 2; Your notes
In this example, the division operator divides the value 10 by 2, resulting in 5
In this example, the modulus operator divides the value 10 by 3 and returns the remainder, which is 1
In this example, the increment operator increases the value of counter by one, resulting in 6
The decrement operator decreases it back to 5
In the first example, without parentheses, the multiplication (*) is performed before the addition (+),
resulting in 14
In the second example, with parentheses, the addition is evaluated first, resulting in 5, which is then
multiplied by 4, resulting in 20
Page 63 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
console.log(x == y);
In this example, the equal to operator compares the value 5 (a number) with the value '5' (a string). Since
JavaScript performs type coercion, the operands are considered equal, resulting in true
console.log(x != y);
In this example, the not equal to operator compares the value 5 with the value '5'. Since JavaScript
performs type coercion and considers the operands equal, the result is false
In this example, the strict equal to operator compares the value 5 with the value '5'. Since the operands
have different types, the result is false
Page 64 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
In this example, the strict not equal to the operator compares the value 5 with the value '5'. Since the Your notes
operands have different types, the result is true
In this example, the greater than operator compares the value 5 with the value 10, resulting in false
The less than operator compares 5 with 10, resulting in true
In this example, the greater than or equal operator compares 5 with 10, resulting in false
The less than or equal to operator compares 5 with 10, resulting in true
Page 65 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
The AND operator (&&) returns true if both operands are true, otherwise returns false:
const x = 5; Your notes
const y = 10;
const z = 15;
In this example, the expression (x < y) && (y < z) evaluates to true because both conditions are true. If any
of the conditions were false, the result would be false
OR operator (||)
The OR operator (||) returns true if at least one of the operands is true, and false if both operands are false:
const a = 5;
const b = 10;
const c = 15;
In this example, the expression (a > b) || (b < c) evaluates to true because the second condition is true,
even though the first condition is false. If both conditions were false, the result would be false
In this example, the ! operator negates the value of false, resulting in true
Page 66 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Page 67 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Page 68 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Nested for loop in JavaScript showing a 2D array with each item in the array being added together to find
the sum of the whole array
Your notes
After the first iteration sum=1 as it's only added the 1st element which is 1
After the 2nd iteration sum=3 as it's added the 2nd element (2) to 1
After the 3rd iteration sum=6 as it's added the 3rd element (3) to the 1 and 2
After the 4th iteration sum=10 as it's added the 4th element (4) to the 1, 2 and 3
The algorithm continues working its way through the rest of the 2nd row and then moves on to the 3rd
let i = 0;
while (i < matrix.length) {
let j = 0;
while (j < matrix[i].length) {
console.log(matrix[i][j]);
j++;
}
i++;
}
EXAM TIP
If you need to check or work out how many times an inner loop is run, multiply the number of
outer loop iterations by the number of inner loop iterations. E.g.
for (let i = 0; i < 3; i++) {
for (let j = 0; j < 5; j++) {
console.log(i * j);
}
}
Page 69 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
The outer loop runs 3 times and the inner loop will run 5 times. To find out the total number of
times the inner loop will run, multiply 3 by 5 = 15
Your notes
Page 70 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Functions in JavaScript
A function is a reusable block of code that performs a specific task or calculation and can be called from
anywhere in the code. Functions can take input parameters (arguments) and return a value.
The syntax for defining a function is as follows:
function functionName(parameter1, parameter2) {
// Code block to perform the task
// Return value;
}
Page 71 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
Your notes
Function in JavaScript
WORKED EXAMPLE
A website sells tickets for sporting events. The website uses HTML, CSS and JavaScript. The
website charges a booking fee of £2.99 on each ticket sold. In addition, if the tickets are
purchased from outside of the UK, £4.99 is added to the booking fee. The booking fee is
calculated using a JavaScript function named bookingfee().
Complete the definition of the bookingfee() function below.
function bookingfee(numtickets, country) {
var nonUKprice = 4.99;
var perTicketPrice = .............................................;
var total = 0;
if (country!="UK") {
total = total + .............................................;
}
total = total + (............................................. * perTicketPrice);
............................................. total;
}
Page 72 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers
Head to www.savemyexams.com for more awesome resources
4 marks
How to answer this question: Your notes
The first blank space is to set the value of the perTicketPrice. The question tells us this is £2.99
The 2nd blank space is to add something to total if the country is not equal to UK. The question
tells us that if the tickets are purchased from outside the UK, £4.99 is added to the booking fee.
This is stored in the nonUKprice variable
The 3rd blank space is something multiplied by perTicketPrice. The question tells us each ticket is
£2.99 so we need to multiply the perTicketPrice by the number of tickets (called numtickets)
The 4th blank space is the last line of the function. As it's a function, a value must be returned. A
value hasn't yet been returned in this function so total must be the value returned
Answer:
Example answer that gets full marks:
function bookingfee(numtickets, country) {
var nonUKprice = 4.99;
var perTicketPrice = 2.99;
var total = 0;
if (country!="UK") {
total = total + nonUKprice;
}
total = total + (numtickets * perTicketPrice);
return total;
}
Procedures in JavaScript
A procedure is similar to a function but does not return a value. Instead, it performs a series of actions
or operations which could be anything the programmer wants the procedure to execute
A procedure is essentially a function without a return statement or with a return statement that has no
value to return
The syntax is the same as for functions:
function procedureName(parameter1, parameter2) {
// Code block to perform actions
// No return statement or return with no value;
}
Page 73 of 73
© 2015-2024 Save My Exams, Ltd. · Revision Notes, Topic Questions, Past Papers