← IGCSE Computer Science Paper 1

Cookie use: tracking user preferences

A cookie that records a user's preferences and browsing habits so a site can tailor what it shows, such as language, layout, suggested products or targeted adverts.

Understanding Cookie use: tracking user preferences in IGCSE Computer Science Paper 1

What it does: The cookie holds browsing habits, which the site uses to show recommended products. The cookie records an interest, so adverts can be matched to what the user likes. A cookie can store settings such as language, so the site shows French each time you return. Cookies record the kinds of pages you visit, and advertisers use this to show adverts matched to your interests. The browser stores a cookie holding the theme preference and sends it back to the site on the next visit. Preference cookies let a site adjust language, layout or suggestions. Encryption is done by HTTPS, not by cookies.

Common mistakes: The program should read the saved language preference from the cookie, so it must be cookie.language. A preference cookie does not hold a password. ENDIF here closes the IF too early, so the ELSE part has nothing to belong to. Line 4 should be ELSE to give the default light theme.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 490–499) and word search (Modules 490–509).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which is an example of a cookie recording a user's preference?
A site remembers you chose French as your languageA site turns your web page into HTML code
Matches
Cookies delete the user's language setting so the site forgets it
↓
Cookies do not delete preferences; they record them so the site can remember the language and tailor pages.
Applying
Meanings
Term
preference cookie
Meaning
A cookie that records a user's preferences and browsing habits so a site can tailor what it shows, such as language, layout, suggested products or targeted adverts.
Practice
Set-Cookie: language=French
Testing
Gaps
: language=French
Check Answer
Spots
1IF cookie EXISTS THEN
2 lang ← cookie.password

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Puffin' badge — Definition Diver, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which is an example of a cookie recording a user's preference?
A. A site turns your web page into HTML code
B. A site remembers you chose French as your language ✓
A cookie can store settings such as language, so the site shows French each time you return.
2. A shop site shows 'Recommended for you' items based on pages you viewed before. What made this possible?
A. Cookies recording your browsing habits ✓
B. The DNS server choosing products for you
Cookies record which products you browsed, so the site can suggest similar ones. DNS only turns domain names into IP addresses.
3. True or false: cookies can record browsing habits so a site can show targeted adverts.
A. False
B. True ✓
Cookies record the kinds of pages you visit, and advertisers use this to show adverts matched to your interests.
4. A user picks dark mode on a website. Next visit it is dark mode again. Which statement best explains this?
A. A cookie stored the theme setting ✓
B. The web server never forgets any visitor
The browser stores a cookie holding the theme preference and sends it back to the site on the next visit.
5. Which is the main purpose of a preference cookie?
A. To tailor what the site shows to the user ✓
B. To encrypt the data sent between browser and server
Preference cookies let a site adjust language, layout or suggestions. Encryption is done by HTTPS, not by cookies.

Match the Pairs

Set-Cookie: lang=fr → Saves the user's chosen language so the site can show pages in French next time
Set-Cookie: theme=dark → Saves the user's layout choice so the site can show dark mode on later visits
A shop records the types of items a user browses so it can suggest similar products → Set-Cookie: viewed=trainers
An advertiser uses a cookie of a user's browsing habits to show targeted adverts → Set-Cookie: interest=football
Cookies delete the user's language setting so the site forgets it → Cookies do not delete preferences; they record them so the site can remember the language and tailor pages.
Recommended products come from the user's monitor size only → Recommendations come from browsing habits recorded in cookies, such as products the user viewed before.

Key Term

preference cookie
A cookie that records a user's preferences and browsing habits so a site can tailor what it shows, such as language, layout, suggested products or targeted adverts.

Fill in the Blanks

1. Set-Cookie: language=French
Hint: Type the name of the HTTP header a server uses to send a cookie to the browser.
2. IF cookie.theme = "dark" THEN page.colour ← "black" ENDIF
Hint: Type the keyword that follows the condition and starts the code to run.
3. Cookie: viewed=Headphones
Hint: Type the header name the browser uses to send its stored cookie back to the server.
4. IF cookie.interest = "football" THEN showAdvert("football boots") ENDIF
Hint: Type the keyword that closes the selection statement.
5. Set-Cookie: language=French; Max-Age=2592000
Hint: Type the cookie attribute that sets how many seconds the preference is kept.

Spot the Error

Question 1
A IF cookie EXISTS THEN
B lang ← cookie.password
C SHOW page IN lang
D ENDIF
Line B — The program should read the saved language preference from the cookie, so it must be cookie.language. A preference cookie does not hold a password.
Question 2
A READ theme FROM cookie
B IF theme = "dark" THEN
C SET background ← black
D ENDIF
E SET background ← white
F ENDIF
Line D — ENDIF here closes the IF too early, so the ELSE part has nothing to belong to. Line 4 should be ELSE to give the default light theme.
Question 3
A READ lastViewed FROM cookie
B items ← SIMILAR(lastViewed)
C FOR EACH item IN lastViewed
D SHOW item
Line C — The loop should go through the list of recommended products (items), not the single last viewed product. It should be FOR EACH item IN items.
Question 4
A READ interests FROM bookmarks
B advert ← MATCH(interests)
C SHOW advert
Line A — A site records browsing habits in a cookie, not in the user's bookmarks. The interests must be read FROM cookie so the advert can be targeted.
Question 5
A INPUT choice
B IF choice = "French" THEN
C lang ← "fr"
D DELETE lang FROM cookie
E ENDIF
Line D — The language preference must be stored in the cookie so the site remembers it next visit. Deleting it would lose the preference. It should be STORE lang IN cookie.

Student with a class code? Join your class →