-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanatomy.html
More file actions
176 lines (153 loc) · 7.32 KB
/
Copy pathanatomy.html
File metadata and controls
176 lines (153 loc) · 7.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Anatomy of a Friendly Error Message</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="anatomy">
<a class="anatomy__back" href="index.html">← Demo</a>
<header class="anatomy__header">
<h1>Anatomy of a Friendly Error Message</h1>
</header>
<div class="anatomy__main">
<div class="anatomy__left">
<!-- Traceback that triggered the error -->
<div class="anatomy__context">
<span class="anatomy__context-label">Error / Trace:</span>
<div class="anatomy__context-code">
<div>Traceback (most recent call last):</div>
<div> File "main.py", line 2, in <module></div>
<div> print("Hello, " + firstname)</div>
<div>NameError: name 'firstname' is not defined</div>
</div>
</div>
<div class="anatomy__card">
<!-- Stage 1: Title + Summary -->
<div class="anatomy__zone" data-zone="1">
<div class="anatomy__zone-head">
<div class="anatomy__zone-badge">1</div>
<div class="anatomy__zone-tag">Explain & Suggest - Title & Summary</div>
</div>
<div class="anatomy__zone-body">
<p class="pfem__title">This variable doesn't exist yet</p>
<p class="pfem__summary">Your code uses the variable <code class="pfem__var">firstname</code>, but it
hasn't been created
yet.
Check <span class="pfem__line">line 2</span>. If you meant to print the text <code
class="pfem__var">firstname</code>, put it in double quotes.</p>
</div>
</div>
<!-- Stage 2a: Why -->
<div class="anatomy__zone" data-zone="2">
<div class="anatomy__zone-head">
<div class="anatomy__zone-badge">2a</div>
<div class="anatomy__zone-tag">Hint & Direct - Why it happened</div>
</div>
<div class="anatomy__zone-body">
<p class="pfem__why">Without speech marks Python treats <code class="pfem__var">firstname</code> as a
variable, and this
variable
does not exist yet.</p>
</div>
</div>
<!-- Stage 2b: What to do -->
<div class="anatomy__zone" data-zone="3">
<div class="anatomy__zone-head">
<div class="anatomy__zone-badge">2b</div>
<div class="anatomy__zone-tag">Hint & Direct - What to do</div>
</div>
<div class="anatomy__zone-body">
<ul class="pfem__steps">
<li>If it is meant to be text, put speech marks around <code class="pfem__var">firstname</code>.</li>
<li>If it is meant to be a variable, make it first (for example: <code>firstname = "Jo"</code>).</li>
<li>Check spelling and capital letters.</li>
</ul>
</div>
</div>
<!-- Stage 3: Patch -->
<div class="anatomy__zone" data-zone="3">
<div class="anatomy__zone-head">
<div class="anatomy__zone-badge">3</div>
<div class="anatomy__zone-tag">Solve - Suggested fix</div>
</div>
<div class="anatomy__zone-body">
<div class="pfem__patch">
<p class="pfem__patch-label">Suggested fix</p>
<pre class="pfem__patch-code"><code>firstname = "Jo"
print("Hello, " + firstname)</code></pre>
</div>
</div>
</div>
</div>
</div>
<div class="anatomy__right">
<!-- Stage description -->
<div class="anatomy__desc">
<div class="anatomy__desc-panel" data-zone="1">
<div class="anatomy__desc-title">Step 1 - Explain & Suggest</div>
<div class="anatomy__desc-text">Explain the error in plain English and why the code can't run. Use
highlighting to draw attention to the relevant line. Suggest which aspect the learner should review - a
typo, a missing definition, a syntax issue - <em>posed as a suggestion</em>, not a directive.</div>
</div>
<div class="anatomy__desc-panel" data-zone="2">
<div class="anatomy__desc-title">Step 2a - Hint & Direct (hint)</div>
<div class="anatomy__desc-text">Provide more specific detail about <strong>why</strong> the error happens.
Give the learner something concrete to reason about before directing them to act.</div>
</div>
<div class="anatomy__desc-panel" data-zone="3">
<div class="anatomy__desc-title">Step 2b - Hint & Direct (direct)</div>
<div class="anatomy__desc-text">Direct the learner - don't suggest. Tell them exactly what to change:
<em>"You need to change X at line Y."</em> Be specific and action-oriented.
</div>
</div>
<div class="anatomy__desc-panel" data-zone="4">
<div class="anatomy__desc-title">Step 3 - Solve</div>
<div class="anatomy__desc-text">Provide a working <strong>solution</strong> with a brief explanation of what
it corrects and why. A last resort - enough to unblock without handing the answer over too early.</div>
</div>
</div>
<div class="anatomy__controls">
<button type="button" class="anatomy__btn anatomy__btn--primary" id="reveal-btn">Next stage
→</button>
<button type="button" class="anatomy__btn anatomy__btn--secondary" id="show-all-btn">Show all stages</button>
<button type="button" class="anatomy__btn anatomy__btn--ghost" id="reset-btn">Reset</button>
</div>
</div>
</div>
</div>
<script>
const TOTAL = 4;
let revealed = 1;
const zones = [...document.querySelectorAll('.anatomy__zone')];
const descPanels = [...document.querySelectorAll('.anatomy__desc-panel')];
const revealBtn = document.getElementById('reveal-btn');
const showAllBtn = document.getElementById('show-all-btn');
const resetBtn = document.getElementById('reset-btn');
function update(next, animate = false) {
revealed = Math.max(1, Math.min(TOTAL, next));
zones.forEach((z, i) => {
const n = i + 1;
const wasRevealed = z.classList.contains('is-revealed');
z.classList.toggle('is-revealed', n <= revealed);
if (animate && n <= revealed && !wasRevealed) {
z.classList.add('just-revealed');
z.addEventListener('animationend', () => z.classList.remove('just-revealed'), { once: true });
}
});
descPanels.forEach((p) => {
p.classList.toggle('is-active', parseInt(p.dataset.zone) === revealed);
});
revealBtn.disabled = revealed >= TOTAL;
revealBtn.textContent = revealed >= TOTAL ? 'All stages revealed' : 'Next stage →';
showAllBtn.disabled = revealed >= TOTAL;
}
revealBtn.addEventListener('click', () => update(revealed + 1, true));
showAllBtn.addEventListener('click', () => update(TOTAL, true));
resetBtn.addEventListener('click', () => update(1));
update(1);
</script>
</body>
</html>