Please check if this code is correct for a client-side Node.js document editor. Please fix if there are any errors const url = "http://localhost:3000/POST";   let undoStack = []; let redoStack = [];   function formatText(command) {     document.execCommand(command, false, null); }   function changeColor() {     const color = prompt("Enter text color code:");     document.execCommand("foreColor", false, color); }   function changeFont() {     const font = prompt("Enter font:");     document.execCommand("fontName", false, font); } function changeFontSize() {     const size = prompt("Enter font size:");     document.execCommand("fontSize", false, size); }   function toUpperCase() {     const selectedText = window.getSelection().toString();     document.execCommand("insertText", false, selectedText.toUpperCase()); }   function toLowerCase() {     const selectedText = window.getSelection().toString();     document.execCommand("insertText", false, selectedText.toLowerCase()); }   function increaseImageSize() {     const selectedImage = document.querySelector('img.resizable');     if (selectedImage) {         const currentWidth = selectedImage.width;         selectedImage.style.width = (currentWidth * 1.2) + 'px';     } } function printDocument() {     const buttons = document.querySelectorAll("button");     buttons.forEach(button => {         button.style.display = "none";     });       const editorContent = document.getElementById("editor").innerHTML;       const printWindow = window.open("", "", "width=600,height=600");       printWindow.document.write("<html><head><title>Print</title><style>@media print { button { display: none; } }</style></head><body>");     printWindow.document.write(editorContent);     printWindow.document.write("</body></html>");     printWindow.document.close();       printWindow.print();       buttons.forEach(button => {         button.style.display = "";     }); }   function undo() {     if (undoStack.length > 0) {         redoStack.push(document.getElementById("editor").innerHTML);         document.getElementById("editor").innerHTML = undoStack.pop();     } }   function redo() {     if (redoStack.length > 0) {         undoStack.push(document.getElementById("editor").innerHTML);         document.getElementById("editor").innerHTML = redoStack.pop();     } } function textAlign(align) {     document.execCommand('justify' + align); } function toggleSettings() {     const settingsBar = document.getElementById("settingsBar");     settingsBar.style.right = settingsBar.style.right === "0px" ? "-290px" : "0px";   }     function toggleMode() {     document.body.classList.toggle("light-mode");     document.body.classList.toggle("dark-mode");   }     document.addEventListener("DOMContentLoaded", function() {     const settingsIcon = document.getElementById("settingsIcon");       if (settingsIcon) {       settingsIcon.addEventListener("click", function() {         toggleSettings();       });     } else {       console.error("Settings icon not found.");     }   });   document.addEventListener("DOMContentLoaded", function() {     const popupBox = document.getElementById("popupBox");     const closePopup = document.getElementById("closePopup");       if (popupBox && closePopup) {         popupBox.style.display = "block";         closePopup.addEventListener("click", function() {             popupBox.style.display = "none";         });     } else {         console.error("Popup elements not found.");     } });

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please check if this code is correct for a client-side Node.js document editor. Please fix if there are any errors

const url = "http://localhost:3000/POST";

 

let undoStack = [];

let redoStack = [];

 

function formatText(command) {

    document.execCommand(command, false, null);

}

 

function changeColor() {

    const color = prompt("Enter text color code:");

    document.execCommand("foreColor", false, color);

}

 

function changeFont() {

    const font = prompt("Enter font:");

    document.execCommand("fontName", false, font);

}

function changeFontSize() {

    const size = prompt("Enter font size:");

    document.execCommand("fontSize", false, size);

}

 

function toUpperCase() {

    const selectedText = window.getSelection().toString();

    document.execCommand("insertText", false, selectedText.toUpperCase());

}

 

function toLowerCase() {

    const selectedText = window.getSelection().toString();

    document.execCommand("insertText", false, selectedText.toLowerCase());

}

 

function increaseImageSize() {

    const selectedImage = document.querySelector('img.resizable');

    if (selectedImage) {

        const currentWidth = selectedImage.width;

        selectedImage.style.width = (currentWidth * 1.2) + 'px';

    }

}

function printDocument() {

    const buttons = document.querySelectorAll("button");

    buttons.forEach(button => {

        button.style.display = "none";

    });

 

    const editorContent = document.getElementById("editor").innerHTML;

 

    const printWindow = window.open("", "", "width=600,height=600");

 

    printWindow.document.write("<html><head><title>Print</title><style>@media print { button { display: none; } }</style></head><body>");

    printWindow.document.write(editorContent);

    printWindow.document.write("</body></html>");

    printWindow.document.close();

 

    printWindow.print();

 

    buttons.forEach(button => {

        button.style.display = "";

    });

}

 

function undo() {

    if (undoStack.length > 0) {

        redoStack.push(document.getElementById("editor").innerHTML);

        document.getElementById("editor").innerHTML = undoStack.pop();

    }

}

 

function redo() {

    if (redoStack.length > 0) {

        undoStack.push(document.getElementById("editor").innerHTML);

        document.getElementById("editor").innerHTML = redoStack.pop();

    }

}

function textAlign(align) {

    document.execCommand('justify' + align);

}

function toggleSettings() {

    const settingsBar = document.getElementById("settingsBar");

    settingsBar.style.right = settingsBar.style.right === "0px" ? "-290px" : "0px";

  }

 

  function toggleMode() {

    document.body.classList.toggle("light-mode");

    document.body.classList.toggle("dark-mode");

  }

 

  document.addEventListener("DOMContentLoaded", function() {

    const settingsIcon = document.getElementById("settingsIcon");

 

    if (settingsIcon) {

      settingsIcon.addEventListener("click", function() {

        toggleSettings();

      });

    } else {

      console.error("Settings icon not found.");

    }

  });

 

document.addEventListener("DOMContentLoaded", function() {

    const popupBox = document.getElementById("popupBox");

    const closePopup = document.getElementById("closePopup");

 

    if (popupBox && closePopup) {

        popupBox.style.display = "block";

        closePopup.addEventListener("click", function() {

            popupBox.style.display = "none";

        });

    } else {

        console.error("Popup elements not found.");

    }

});

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Form and its Elements
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education