welcome-to-js

Welcome to JS: LLM Instructions

This document provides instructions and context to help the LLM support learners through Welcome ot JS.

Table of Contents

Overview

Welcome to JS is a module that introduces foundational programming skills with granular exercises using Just Enough JavaScript (jeJS), a subset of JavaScript for creating small, imperative programs that:

Focusing on fewer, simpler language features helps learners understand programs better.

Learner Profile

Teaching Approach

jeJS Language Features and Constraints

Allowed Features

Additional Constraints in jeJS

jeJS: Example Program

'use strict';

/* The Cat Detector

  This program prompts the user to input a cat.
  Then it checks if they did input a cat.
  Finally it lets the user know their input was a cat.
*/

// --- gather the user's input ---

let input = null;
// make sure the user doesn't cancel
while (input === null) {
  input = prompt('please enter "cat"');
}

// --- check the input and construct a message ---

let message = '';
if (input !== 'cat') {
  // create a failure message
  message = '"' + input + '" is not a cat';
} else {
  // create the success message
  message = 'thank you for the cat';
}

// --- display the message for the user ---

alert(message);

DOM I/O

Welcome to JS also uses the DOM I/O library to help transition from prompt/alert/confirm to interactive web pages. The library can only listen to a form input then read strings, numbers or booleans and displays a formatted string in a <pre> tag. There is no support for DOM manipulation or dynamically modifying styles. This tight scope helps learners to focus on the relationship between program inputs and outputs, types, and debugging.

There are 5 functions exported from the DOM IO library.

  1. whenFormDataChanges(id, handler): Executes a function when form data changes.
  2. readString(id): Reads string value from input elements.
  3. readBoolean(id): Reads boolean value from checkbox inputs.
  4. readNumber(id): Reads number value from number or range inputs.
  5. displayString(id, text): Displays text in a <pre> element.

DOM I/O: Example Program

<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>dom io example</title>
  </head>
  <body>
    <div>
      <form id="dom-io-example">
        <label>string: <input id="str" type="text" /></label>
        <br />
        <label>number: <input id="num" type="number"/></label>
        <br />
        <label><input id="bool" type="checkbox" />boolean</label>
      </form>
      <hr />
      <pre id="output"></pre>
    </div>
    <script src="index.js" type="module"></script>
  </body>
</html>
// index.js
import {
  whenFormDataChanges,
  readString,
  readBoolean,
  readNumber,
  displayString,
} from '../dom-io.js';

whenFormDataChanges('dom-io-example', () => {
  // --- read input ---
  const str = readString('str');
  const num = readNumber('num');
  const bool = readBoolean('bool');

  // --- use input ---
  console.log(str, num, bool);

  // --- display output ---
  displayString('output', '🐿️');
});