PeaBox Lab › PeaLang › Learn › Chapter 2 › Lesson 5

Part I — Foundations · Chapter 2 · Lesson 5 of 5 · 5 min read

Chapter 2 Checkpoint: Unit Converter

Checkpoint level: Foundation

Purpose: Integrate lexical rules, values, declarations, assignment, expressions, precedence, interpolation, output design, and diagnostics in one conversion program.

Checkpoint outcomes

By completing this checkpoint, you will demonstrate that you can:

Project model

Because the foundational language has no general input statement, this command-line checkpoint is driven by editable source values. The learner changes conversion and input_value at the top of the file, then formats, checks, and runs it. A later host-integration version can obtain those values interactively and pass them through a validated boundary.

2C.1 Supported conversions

ModeFormula
c_to_ffahrenheit = celsius * 9 / 5 + 32
f_to_ccelsius = (fahrenheit - 32) * 5 / 9
km_to_mimiles = kilometres * 0.621371
mi_to_kmkilometres = miles / 0.621371
kg_to_lbpounds = kilograms * 2.2046226218
lb_to_kgkilograms = pounds / 2.2046226218

2C.2 Required inputs and outputs

Declare these editable scenario inputs:

let conversion = "c_to_f"
let input_value = 25

The program must print:

2C.3 Validation rules

2C.4 Implementation constraints

2C.5 Acceptance criteria

2C.6 Reference implementation

Attempt the checkpoint independently before comparing your source with this version.

const miles_per_km = 0.621371
const pounds_per_kg = 2.2046226218
let conversion = "c_to_f"
let input_value = 25
let result = 0
let source_unit = ""
let target_unit = ""
let formula_code = ""
let valid = true
let message = "Conversion complete"
if conversion == "c_to_f" {
    source_unit = "°C"
    target_unit = "°F"
    formula_code = "C_TO_F"
    result = (input_value * 9 / 5) + 32
} else if conversion == "f_to_c" {
    source_unit = "°F"
    target_unit = "°C"
    formula_code = "F_TO_C"
    result = (input_value - 32) * 5 / 9
} else if conversion == "km_to_mi" and input_value >= 0 {
    source_unit = "km"
    target_unit = "mi"
    formula_code = "KM_TO_MI"
    result = input_value * miles_per_km
} else if conversion == "mi_to_km" and input_value >= 0 {
    source_unit = "mi"
    target_unit = "km"
    formula_code = "MI_TO_KM"
    result = input_value / miles_per_km
} else if conversion == "kg_to_lb" and input_value >= 0 {
    source_unit = "kg"
    target_unit = "lb"
    formula_code = "KG_TO_LB"
    result = input_value * pounds_per_kg
} else if conversion == "lb_to_kg" and input_value >= 0 {
    source_unit = "lb"
    target_unit = "kg"
    formula_code = "LB_TO_KG"
    result = input_value / pounds_per_kg
} else {
    valid = false
    message = "Unsupported mode or invalid non-temperature input"
}
print "Mode: {conversion}"
print "Valid: {valid}"
print "Message: {message}"
if valid {
    print "Input: {input_value} {source_unit}"
    print "Result: {result} {target_unit}"
    print "Formula: {formula_code}"
}

2C.7 Required test matrix

CaseModeInputExpected result
Ac_to_f032 °F
Bf_to_c320 °C
Cc_to_f-40-40 °F
Dkm_to_mi106.21371 mi
Emi_to_km1Approximately 1.609344 km
Fkg_to_lb12.2046226218 lb
Glb_to_kg2.2046226218Approximately 1 kg
Hkm_to_mi-1Invalid
Iunknown10Invalid

Cases A–C test important temperature points, including the value where Celsius and Fahrenheit are equal. Cases H and I test validation.

2C.8 Round-trip tests

A round trip converts from one unit to another and back. Small floating-point differences may occur, so compare with an explicit tolerance rather than requiring exact decimal text.

Record the original value, intermediate value, returned value, absolute difference, and acceptable tolerance.

2C.9 Validation workflow

2C.10 Deliberate diagnostic exercises

Create temporary variants that demonstrate:

For each, record the processing stage, location, message or invalid output, root cause, and minimal correction.

2C.11 Submission package

2C.12 Assessment rubric

AreaEvidence of mastery
CorrectnessAll formulas and units are correct.
ValidationUnsupported modes and invalid non-temperature inputs are rejected.
Expression reasoningParentheses, precedence, and divisor safety are explained.
DeclarationsConstants and mutable bindings are chosen deliberately.
OutputMessages are labeled, unit-aware, deterministic, and safe.
DiagnosticsFailures are classified and corrected minimally.
TestingBoundary, invalid, and round-trip cases are covered.
Host designInteractive input is assigned to a validated host boundary.

Completion standard: Every required valid case passes, invalid cases are rejected clearly, and the learner can explain every expression and output field.

2C.13 Reflection questions

Chapter 2 summary

You can now describe PeaLang source lexically, declare and update bindings, reason about nested scope, evaluate expressions by precedence, use short-circuit logic, build interpolated output, and triage basic diagnostics. The unit-converter checkpoint integrates those skills in a complete program.

Transition to Chapter 3

Chapter 3 develops control flow in depth. The next lesson covers Boolean logic and conditional branches, including branch design, condition tables, boundary analysis, and readable policy ordering.

Checkpoint status: Approved.

← Previous Next →