Skip to content

Commit 371aa8c

Browse files
Add question navigation: URL params, direct input, and test validation system
Features: - Navigate via URL: ?question=1000 - Input field to jump to any question (1-1000) - Hidden test cases with automatic validation - Mark complete only when all tests pass - Test results UI with pass/fail indicators
1 parent 21c909a commit 371aa8c

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

docs/editor.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ <h2>
3636
</h2>
3737
<div class="question-nav">
3838
<button id="prev-question" class="btn-icon" title="Previous"><i class="fas fa-chevron-left"></i></button>
39+
<input type="number" id="question-input" min="1" max="1000" placeholder="#" style="width: 60px; text-align: center; padding: 0.5rem; border: 1px solid #dee2e6; border-radius: 4px;">
40+
<button id="goto-question" class="btn-icon" title="Go to question"><i class="fas fa-arrow-right"></i></button>
3941
<button id="next-question" class="btn-icon" title="Next"><i class="fas fa-chevron-right"></i></button>
4042
<button id="random-question" class="btn-icon" title="Random"><i class="fas fa-random"></i></button>
4143
</div>

docs/js/editor.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,17 @@ async function initializeEditor() {
2323
}
2424

2525
document.addEventListener('DOMContentLoaded', function() {
26-
// Get level from URL parameter
26+
// Get level and question from URL parameters
2727
const urlParams = new URLSearchParams(window.location.search);
2828
if (urlParams.has('level')) {
2929
currentLevel = urlParams.get('level');
3030
}
31+
if (urlParams.has('question')) {
32+
const questionParam = parseInt(urlParams.get('question'));
33+
if (questionParam >= 1 && questionParam <= 1000) {
34+
currentQuestion = questionParam;
35+
}
36+
}
3137

3238
// Initialize editor and load questions
3339
initializeEditor();
@@ -40,9 +46,17 @@ document.addEventListener('DOMContentLoaded', function() {
4046
document.getElementById('prev-question').addEventListener('click', prevQuestion);
4147
document.getElementById('next-question').addEventListener('click', nextQuestion);
4248
document.getElementById('random-question').addEventListener('click', randomQuestion);
49+
document.getElementById('goto-question').addEventListener('click', gotoQuestion);
4350
document.getElementById('show-hints').addEventListener('click', toggleHints);
4451
document.getElementById('clear-output').addEventListener('click', clearOutput);
4552

53+
// Enter key on question input
54+
document.getElementById('question-input').addEventListener('keypress', function(e) {
55+
if (e.key === 'Enter') {
56+
gotoQuestion();
57+
}
58+
});
59+
4660
// Track start time
4761
startTime = Date.now();
4862
});
@@ -351,6 +365,18 @@ function nextQuestion() {
351365
}
352366
}
353367

368+
function gotoQuestion() {
369+
const input = document.getElementById('question-input');
370+
const questionNum = parseInt(input.value);
371+
372+
if (questionNum >= 1 && questionNum <= 1000) {
373+
loadQuestion(questionNum);
374+
input.value = ''; // Clear input
375+
} else {
376+
alert('Please enter a question number between 1 and 1000');
377+
}
378+
}
379+
354380
function randomQuestion() {
355381
const random = Math.floor(Math.random() * 1000) + 1;
356382
loadQuestion(random);

0 commit comments

Comments
 (0)