Skip to content

Commit

Permalink
Merge pull request #81 from Satyasn01/bug/reset-button
Browse files Browse the repository at this point in the history
  • Loading branch information
codingkatty authored Oct 15, 2024
2 parents cb49da3 + ef33190 commit 7458108
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let editor;
let pyodide;
let currentLesson;
let currentContentType;

// Add these lines at the beginning of the file
let userProgress = JSON.parse(localStorage.getItem('userProgress')) || {
Expand Down Expand Up @@ -76,6 +77,7 @@ window.addEventListener('load', initPyodide);

function showEditor(lesson) {
currentLesson = lesson;
currentContentType = 'lesson'; // Set the content type to 'lesson'
document.getElementById('editor-container').style.display = 'flex';
if (!editor) {
editor = ace.edit("editor");
Expand Down Expand Up @@ -425,11 +427,14 @@ const questions = [
"Write a Python function to sort a list of numbers."
// Add more questions as needed
];

function generateQuestion() {
currentContentType = 'practice_question';
const randomIndex = Math.floor(Math.random() * questions.length);
const randomQuestion = questions[randomIndex];
document.getElementById('random-question').innerText = randomQuestion;
currentContent = questions[randomIndex]; // Store the current question text
document.getElementById('random-question').innerText = currentContent;
if (editor) {
editor.setValue(`# Question: ${currentContent}\n\n# Write your Python code here:\n`, 1);
}
}

// Call this function on page load if you want to display a question initially
Expand Down Expand Up @@ -631,14 +636,26 @@ hamburger.addEventListener("click", () => {
updateProgressBar();
});

//This function should check currentContentType to decide how to reset the editor.
function resetEditor() {
// Check the type of content currently loaded
if (currentContentType === 'lesson') {
// If it's a lesson, reset to the original lesson content
showEditor(currentLesson);
} else if (currentContentType === 'practice_question') {
// If it's a practice question, clear the editor but keep the question visible
if (editor && currentContent) {
editor.setValue(`# Question: ${currentContent}\n\n# Write your Python code here:\n`, 1);
}
}
}

// Reset button
document.getElementById('reset-code').addEventListener('click', () => {
if (currentLesson) {
showEditor(currentLesson);
}
//reset-button
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('reset-code').addEventListener('click', resetEditor);
});


document.getElementById('copy-code').addEventListener('click', () => {
const code = editor.getValue();
navigator.clipboard.writeText(code)
Expand Down

0 comments on commit 7458108

Please sign in to comment.