One tap, two worlds
You tap Order on a food app. The button changes colour at once. A moment later, the app says "Order sent".
Two different programs did this. One runs on your phone. One runs on a computer far away.
They are often written in different languages. Today you learn why, and you write both.
Key words
| Word | What it means | Example |
|---|---|---|
| Front end | The part the user sees and touches. | buttons, forms |
| Back end | The part on a server that holds the rules. | work out the price |
| Server | A computer that answers requests from other computers. | |
| Browser | The program that shows web pages. | |
| Request | A message asking the back end to act. | |
| Database | An organised store of data that programs can search and change. | |
| Language | A set of rules for writing instructions for a computer. | |
| Data type | The kind of value something is. | A price is a number |
| SQL | The language for asking a database for data. |
The cells students fill in are left blank in this preview.
Front end and back end
flowchart LR
user([User]) --> front[Front end: HTML, CSS, JavaScript in the browser]
front -->|request| back[Back end: Python on the server]
back -->|SQL| db[(Database)]
db -->|rows| back
back -->|answer| front
Check: where does it run?
Have a go
Check: where does it run?
3 questionsThe five languages in the spec
| Language | Where it runs | Often used for | Good to know |
|---|---|---|---|
| Python 3.10 or later | Server | Back end, data, scripts | Short and clear code. Many libraries |
| JavaScript | Browser and server | Front end, and back end with Node (JavaScript on a server) | The main language every browser runs |
| C# | Server, desktop, games | Back end, Windows apps, Unity games (Unity is a tool for making games) | Strict about data types. Made by Microsoft |
| PHP | Server | Websites and back ends | Built for the web. Runs a lot of older sites |
| SQL | Database | Asking for and changing data | Only for data, so you use it with another language |
The cells students fill in are left blank in this preview.
A back end in Python
def price_with_delivery(total, fee):
return total + fee
order = [8, 3, 2]
total = sum(order)
print("Total", total)
print("To pay", price_with_delivery(total, 3))
# The server does the sums. Change the order and run again.
Make a free account to save your work and track your progress.
A front end in JavaScript
<button id="go">Order</button>
<p id="msg">Nothing yet.</p>Make a free account to save your work and track your progress.
Why more than one language?
Important
Every browser runs JavaScript, so the front end uses it. A server can use any language. The database speaks SQL. Choose each language for the job it does best.
Match the job to the language
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Write the back end in Python
You are the back end of a food shop. Prices are in pence, so they are whole numbers. Finish delivery_fee and order_summary. Free delivery starts at 2000 pence. Press Run Tests.
def delivery_fee(total_pence):
# An order of 2000 pence (20 pounds) or more has free delivery.
# Under that, delivery costs 300 pence.
return None
def order_summary(prices):
# prices is a list of whole numbers (pence).
# Give back a dictionary: {"count": ..., "total": ..., "fee": ...}
return None
Make a free account to save your work, or press Start lab to work through the whole lesson.
Write the front end logic
Now write two JavaScript functions for the front end. formatPrice shows pence as pounds. isValidQuantity checks what the user typed in the quantity box. Press Run Tests.
function formatPrice(pence) {
// 350 pence becomes "£3.50". 5 pence becomes "£0.05".
return null;
}
function isValidQuantity(text) {
// A quantity is a whole number from 1 to 10, written as text.
// "3" is valid. "0", "11", "2.5" and "abc" are not.
return null;
}
Make a free account to save your work, or press Start lab to work through the whole lesson.
Build the order page
Finish the order page. When the user presses Add, show the new count in the Basket line. The button must not let the count go over 10. When it reaches 10, show the words "Basket is full". Your teacher marks this task.
<h1>Pizza shop</h1>
<button id="add">Add a pizza</button>
<p id="basket">Basket: 0</p>Make a free account to save your work, or press Start lab to work through the whole lesson.
Key words crossword
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Exit quiz
Have a go