You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.2 KiB

8 months ago
  1. var outputs = [];
  2. var simulator = [];
  3. var graph = [];
  4. function run() {
  5. var input1 = document.getElementById("firstInput").value;
  6. var input2 = document.getElementById("secondInput").value;
  7. if (!input1 || !input2) {
  8. Toastify({
  9. text: "Input field cannot be empty!",
  10. duration: 3000,
  11. close: true,
  12. gravity: "top",
  13. }).showToast();
  14. } else {
  15. outputFunction(input1, input2);
  16. simulatorFunction(input1, input2);
  17. graphFunction(input1, input2);
  18. updateTextarea(getActiveTabContent());
  19. var input1 = (document.getElementById("firstInput").value = "");
  20. var input2 = (document.getElementById("secondInput").value = "");
  21. // Query for only the checked checkboxes and put the result in an array
  22. //Printing values one by one
  23. // let checked = document.querySelectorAll("input[type='checkbox']:checked");
  24. // console.clear();
  25. // checked.forEach(function (cb) {
  26. // console.log(cb.value);
  27. // });
  28. //Saving values in array
  29. let checked = document.querySelectorAll("input[type='checkbox']:checked");
  30. console.clear();
  31. let checkedValues = Array.from(checked).map((cb) => cb.value);
  32. console.log(checkedValues);
  33. }
  34. }
  35. //Functions
  36. function simulatorFunction(input1, input2) {
  37. var result = input1 + input2;
  38. simulator.push(result);
  39. }
  40. function outputFunction(input1, input2) {
  41. var result = input1 + " " + input2;
  42. outputs.push(result);
  43. }
  44. function graphFunction(input1, input2) {
  45. var result = input1 + "-" + input2;
  46. graph.push(result);
  47. }
  48. function getActiveTabContent() {
  49. var activeTabId = document.querySelector(".rightNav.active").id;
  50. switch (activeTabId) {
  51. case "output":
  52. return outputs;
  53. case "simulator":
  54. return simulator;
  55. case "graph":
  56. return graph;
  57. default:
  58. return [];
  59. }
  60. }
  61. function updateTextarea(data) {
  62. scrollableOutput.innerHTML = data.join("\r\n");
  63. }
  64. // Add click event listeners to tab links
  65. document.querySelectorAll(".rightNav").forEach((navLink) => {
  66. navLink.addEventListener("click", function (event) {
  67. event.preventDefault();
  68. document.querySelectorAll(".rightNav").forEach((navLink) => {
  69. navLink.classList.remove("active");
  70. });
  71. this.classList.add("active");
  72. updateTextarea(getActiveTabContent());
  73. });
  74. });