Information Technology • Programming for the Web

Web Scripting Sandbox

Challenge

    HTMLpage.html read only

    
          

    JSscript.js

    Preview

    Console

    Web Scripting Sandbox — Explanation

    How to use it. Each challenge gives you a web page (page.html, which you can read but not change) and asks you to write its script (script.js). ▶ Run puts your script into the page in the preview, where you can use it: type in the boxes, click the buttons. Anything your script writes with console.log() or alert(), and any error, shows in the console. ✓ Check runs the challenge's tests on your script: it types into the boxes and clicks the buttons for you, and reports what happened. Stuck? Take a hint, or look at a model answer. Playground lets you change the HTML too.

    The ideas.

    Safe to experiment. Your code runs in a sandbox, separate from this page. A loop that never ends is stopped after a second or two, and the sandbox is restarted.

    Common mistakes: getElementByID (it's Id) and other wrong capitals (JavaScript is case-sensitive); using = (assignment) when you mean === (comparison); adding inputs' values without Number(); a boundary off by one (> where it should be >=); a loop whose condition never becomes false; forgetting to stop the form when it's invalid; adding to a list without clearing it first.

    Objective: Cambridge International A Level IT (9626), programming for the web: JavaScript in a web page; variables, constants and data types; operators; selection (if, switch); iteration (for, while, do … while); functions; arrays; events; changing the page (the DOM); outputs (innerHTML, console, alert); and form validation.

    Where this fits

    • Cambridge: Cambridge A Level Information Technology (9626)
    • NCEA Level 1 Digital Technologies: 92004 Create a computer program
    • NCEA Level 2 Digital Technologies: 91893 Use advanced techniques to develop a digital media outcome; 91896 Use advanced programming techniques to develop a computer program
    • Pearson Edexcel International: Edexcel International A Level Information Technology

    Web Scripting Sandbox — Key Terms

    Key concepts in English, with te reo Māori, Chinese (Simplified) and Korean.

    EnglishTe reo Māori中文(简体)한국어What it means on this page
    JavaScriptno attested termJavaScript(脚本语言)자바스크립트A programming language run by the web browser, which makes web pages respond to the user.
    Eventno attested term事件이벤트Something that happens on a web page, such as a click, a key press or a form being submitted, which can run code (an event handler).
    Document Object Model (DOM)no attested term文档对象模型(DOM)문서 객체 모델(DOM)The web page as the browser holds it: a tree of elements that a script can find (getElementById) and change.
    Consoleno attested term控制台콘솔A panel where a script's console.log() messages and its errors are shown, used for testing.
    Variabletāupe变量변수A named store for a value that can change while the script runs, made with let (or const, for one that can't).
    Selectionno attested term选择结构선택 구조Choosing which code runs, with if … else or switch.
    Iteration (loop)koromeke循环(迭代)반복(루프)Repeating code with for, while or do … while.
    Functiontaumahi函数함수A named block of code, called by its name with parameters, that can return a value.
    Arrayhuānga数组배열An ordered list of values under one name; the first is index 0, e.g. cities[0].
    Validationno attested term数据验证 (shùjù yànzhèng)유효성 검사 (yuhyoseong geomsa)An automatic check by the computer, as data is entered, that the data is reasonable and follows set rules; it cannot tell whether the data is correct.
    Presence Checkno attested term存在性检查 (cúnzàixìng jiǎnchá)존재 검사 (jonjae geomsa)A validation check that a required field has not been left blank.
    Range Checkno attested term范围检查 (fànwéi jiǎnchá)범위 검사 (beomwi geomsa)A validation check that a number or date lies between a lowest and a highest value.
    Length Checkno attested term长度检查 (chángdù jiǎnchá)길이 검사 (giri geomsa)A validation check that data has the right number of characters, for example a password of 8 to 20 characters.
    Format Checkno attested term格式检查 (géshì jiǎnchá)형식 검사 (hyeongsik geomsa)A validation check that data follows a set pattern, for example a date written as DD/MM/YYYY.

    On the te reo Māori column. Terms marked as gaps have no attested equivalent in the sources checked — Karaitiana Taiuru's Dictionary of Māori Computer and Social Media Terms, Paekupu, the Reserve Bank's te reo financial glossary, NZQA and Te Aka. No coinage is printed as though it were established; where a class needs one, commission it from Te Taura Whiri i te Reo Māori and credit the translator. Te reo Māori is not italicised and takes no plural "s".