Building "wRiteFormula": An AI-Powered Journey to an Engaging Chemistry Game
Creating effective educational tools means bridging the gap between pedagogical intent and technical execution. This post documents the development of wRiteFormula v2, an interactive chemistry game for secondary school students in Singapore. It showcases how AI collaboration—leveraging Trae.ai, the Cline Extension, and Google’s Gemini 2.5 Pro model—accelerated the process of transforming a static PDF specification into a dynamic web-based learning tool.
The Objective: From PDF Specification to Playable Game
The goal was ambitious: convert a detailed PDF into a fully functional, curriculum-aligned, and engaging chemistry game using only HTML, CSS, and JavaScript—fit for embedding in Singapore’s Student Learning Space (SLS). The game targeted students aged 13–16 (Secondary 3/4), focusing on the correct formation and naming of ionic compounds.
| wRiteFormulaPDF/ wRiteFormulaPDF_SLS_20250424_210409.zip |
Key Requirements:
Curriculum-aligned ionic bonding logic
Intuitive tile-based gameplay with responsive feedback
Gamified elements like scoring and streaks
MCQs based on student misconceptions
Laying the Groundwork: From Idea to Codebase
We began by breaking down the PDF into actionable tasks and setting up the foundational code using the write_to_file tool in Cline:
<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
<title>wRiteFormula v2</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>wRiteFormula v2 Challenge</h1>
<!-- Interactive Elements -->
<script src="script.js"></script>
</body>
</html>From there, script.js and style.css served as the main engines of game logic and design.
Core Gameplay Implementation
Development centered around the script.js file. Major milestones included:
Ion Database (
allIons): Each ion was defined with its name, charge, type, and oxidation state.Level Logic (
levelDefinitions): Difficulty progressed over 20 levels, with each level offering specific cation/anion combinations.Tile Grid Generation (
populateIonGrid): Dynamically populated based on level, with responsive layouts.User Interaction (
handleTileClick): Enabled users to select one cation and one anion, activating a “Form Compound” button.Chemical Formula Calculation (
calculateFormula): Used charge balancing via LCM and included special formatting for polyatomic ions.Compound Naming (
generateCompoundName): Respected IUPAC naming conventions, including Roman numerals.Quiz Mechanism (MCQs):
Randomized question type (name or formula)
Plausible distractors based on real student errors
Instant feedback and scoring logic
Iterative Improvements and Bug Fixes
New Levels
| wRiteFormulaPDF/ wRiteFormulaPDF_SLS_20250424_210409.zip |
Initial deployment covered levels 1–15.
| wRiteFormulaPDF/ wRiteFormulaPDF_SLS_20250424_210409.zip |
Based on user feedback, levels 16–20 were added with rare ions like
CrO₄²⁻, CN⁻, and Pt²⁺.Debugging Highlights
ReferenceError: charge2: Scope error resolved by elevatinggcdand replacing local variables.SyntaxError: Unexpected token '<': Caused by HTML tags in feedback strings—resolved by safely extracting text from elements before injection.
Enhanced Engagement
Sound Effects: Triggered on tile selection and quiz results using
.play()onAudioobjects.Responsive Design:
Reduced tile count on mobile
Used CSS Grid with
auto-fitand media queries
Scoring Adjustment: Simplified scoring logic to match student feedback.
Final Touches: Packaging and Publishing
Analytics: Added Google Analytics tracking for usage insights.
Attribution: Credit line included at the bottom of
index.htmlfor Trae.ai, Cline, Gemini 2.5 Pro, and iwant2study.org.SLS Zip Package: A ZIP archive containing only the runtime essentials (
index.html,style.css,script.js,sounds/) was created via:
tar -a -c -f wRiteFormula_SLS_20250424_210409.zip index.html script.js style.css soundsAI as a Development Partner
This project illustrates the power of embedding AI into the development pipeline:
| Task | AI Contribution |
|---|---|
| Requirement Parsing | Extracted structured logic from PDFs and images |
| Code Generation | Built and edited HTML, CSS, and complex JavaScript |
| File Operations | Read, wrote, replaced content in real-time |
| Debugging | Diagnosed errors and proposed multiple fixes |
| Packaging | Created distributable files for SLS |
The collaborative interplay between AI and human insight enabled rapid prototyping, iterative enhancement, and classroom-ready deployment—all within days, not weeks.
Enhancement
| Require that the number of ions selected correspond to what’s needed for the charges to be balanced in an ionic compound |
Conclusion
wRiteFormula v2 stands as a testament to the potential of AI-augmented development in education. By blending clear educational goals with powerful AI tooling, what began as a static PDF became a dynamic, gamified learning experience—scalable, interactive, and aligned with modern pedagogy.
Whether you're an educator, developer, or edtech enthusiast, this project demonstrates how AI can help build the future of learning—one compound at a time.
No comments:
Post a Comment