Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

OS 6.1 (1 of 10): Two languages, one product

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

55 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

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

WordWhat it meansExample
Front endThe part the user sees and touches.buttons, forms
Back endThe part on a server that holds the rules.work out the price
ServerA computer that answers requests from other computers.
BrowserThe program that shows web pages.
RequestA message asking the back end to act.
DatabaseAn organised store of data that programs can search and change.
LanguageA set of rules for writing instructions for a computer.
Data typeThe kind of value something is.A price is a number
SQLThe 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 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

The five languages in the spec

LanguageWhere it runsOften used forGood to know
Python 3.10 or laterServerBack end, data, scriptsShort and clear code. Many libraries
JavaScriptBrowser and serverFront end, and back end with Node (JavaScript on a server)The main language every browser runs
C#Server, desktop, gamesBack end, Windows apps, Unity games (Unity is a tool for making games)Strict about data types. Made by Microsoft
PHPServerWebsites and back endsBuilt for the web. Runs a lot of older sites
SQLDatabaseAsking for and changing dataOnly 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

Code: 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

Code: web
<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.

Code: python
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.

Code: node
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.

Code: web
<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

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.