Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions harness/js-scaffold/PROMPT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# JS Quiz Scaffold

A minimal vanilla JS quiz that checks answers and colors buttons.

## Rules
- Do not change the correct answer without updating specs/quiz.md
- Tests must pass after every change: `npm test`
- Do not add frameworks or large dependencies
12 changes: 12 additions & 0 deletions harness/js-scaffold/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# JS Scaffold Example

Shows how Ralph works with a frontend JS project.

## Structure
- `PROMPT.md` — rules Ralph must follow
- `specs/` — behavior specs Ralph must not break
- `npm test` — fails if behavior is broken

## Usage
npm install
npm test
47 changes: 47 additions & 0 deletions harness/js-scaffold/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quiz</title>
<script src="./quiz.js" type="module" defer></script>
<style>
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin: 0;
}
h1{
font-size: 3.4rem;
}
p{
font-size: 1.5rem;
text-align: center
}
button{
padding-inline: 1.5rem;
width: 100%;
font-size: 1rem;
padding-block: 0.5rem;
display: block;
margin-bottom: 1rem;
}
</style>
</head>
<body>
<main>
<header>
<h1> Quiz Test </h1>
</header>
<section>
<p>NaN === NaN</p>
<button id="btn-true" type="button">True</button>
<button id="btn-false" type="button">False</button>
</section>
</main>
</body>

</html>
8 changes: 8 additions & 0 deletions harness/js-scaffold/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "js-scaffold" ,
"type": "module" ,
"scripts": {
"test": "node --test test.js"
}

}
21 changes: 21 additions & 0 deletions harness/js-scaffold/quiz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export function checkAnswer(answer){
const correctAnswer = false;
return answer===correctAnswer
}
function testQuiz(){
const trueBtn=document.getElementById('btn-true');
const falseBtn=document.getElementById('btn-false');
trueBtn.addEventListener('click',()=>{
const isCorrect = checkAnswer(true);
trueBtn.style.background = isCorrect ? '#d4edda' : '#f8d7da';
falseBtn.style.background=''
})
falseBtn.addEventListener('click',()=>{
const isCorrect = checkAnswer(false);
falseBtn.style.background = isCorrect ? '#d4edda' : '#f8d7da';
trueBtn.style.background=''
})
}
if(typeof document!=='undefined'){
testQuiz()
}
6 changes: 6 additions & 0 deletions harness/js-scaffold/specs/quiz.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Quiz Specs

## checkAnswer(answer)
- returns true when answer matches the correct answer
- returns false otherwise
- correct answer for "NaN === NaN" is false
8 changes: 8 additions & 0 deletions harness/js-scaffold/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import test from 'node:test';
import assert from 'node:assert';
import { checkAnswer } from './quiz.js';
test(' Quiz - checkAnswer function',()=>{
assert.strictEqual( checkAnswer(false) , true );
assert.strictEqual(checkAnswer(true) , false)
})

Loading