Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

User:BakiDance/common.js: Difference between revisions

No edit summary
No edit summary
Line 2: Line 2:
var parentElement = document.getElementById('simple-calc__container');
var parentElement = document.getElementById('simple-calc__container');


// Get the span elements to be replaced
// Get the span element to be replaced
var spanElements = parentElement.getElementsByTagName('span');
var spanElement = document.getElementById('simple-calc__rcalculate');


// Convert spanElements to an array
// Create the button element
var spanArray = Array.from(spanElements);
var calculateButton = document.createElement('button');
calculateButton.id = 'calculate-btn';
calculateButton.textContent = 'Calculate';


// Loop through each span element
// Add click event listener to the button
spanArray.forEach(function (spanElement) {
calculateButton.addEventListener('click', function () {
   // Create the button element
   // Get the input values
   var calculateButton = document.createElement('button');
   var inputValue1 = parseFloat(document.getElementById('simple-calc__input1').value);
   calculateButton.id = 'calculate-btn';
   var inputValue2 = parseFloat(document.getElementById('simple-calc__input2').value);
   calculateButton.textContent = 'Calculate';
   var inputValue3 = parseFloat(document.getElementById('simple-calc__input3').value);


   // Add click event listener to the button
   // Perform calculations
   calculateButton.addEventListener('click', function () {
   var i = inputValue1;
    // Get the input values
  var l = inputValue2;
    var inputValue1 = parseFloat(document.getElementById('simple-calc__input1').value);
  var j = inputValue3;
    var inputValue2 = parseFloat(document.getElementById('simple-calc__input2').value);
    var inputValue3 = parseFloat(document.getElementById('simple-calc__input3').value);


    // Perform calculations
  // Output the results
    var i = inputValue1;
  console.log('i = ' + i);
    var l = inputValue2;
  console.log('l = ' + l);
    var j = inputValue3;
  console.log('j = ' + j);


    // Output the results
  // You can perform further calculations or actions based on the input values here
    console.log('i = ' + i);
});
    console.log('l = ' + l);
    console.log('j = ' + j);


    // You can perform further calculations or actions based on the input values here
// Replace the span element with the button
  });
spanElement.parentNode.replaceChild(calculateButton, spanElement);
 
  // Replace the span element with the button
  spanElement.parentNode.replaceChild(calculateButton, spanElement);
});





Revision as of 01:23, 25 October 2023

// Get the parent element
var parentElement = document.getElementById('simple-calc__container');

// Get the span element to be replaced
var spanElement = document.getElementById('simple-calc__rcalculate');

// Create the button element
var calculateButton = document.createElement('button');
calculateButton.id = 'calculate-btn';
calculateButton.textContent = 'Calculate';

// Add click event listener to the button
calculateButton.addEventListener('click', function () {
  // Get the input values
  var inputValue1 = parseFloat(document.getElementById('simple-calc__input1').value);
  var inputValue2 = parseFloat(document.getElementById('simple-calc__input2').value);
  var inputValue3 = parseFloat(document.getElementById('simple-calc__input3').value);

  // Perform calculations
  var i = inputValue1;
  var l = inputValue2;
  var j = inputValue3;

  // Output the results
  console.log('i = ' + i);
  console.log('l = ' + l);
  console.log('j = ' + j);

  // You can perform further calculations or actions based on the input values here
});

// Replace the span element with the button
spanElement.parentNode.replaceChild(calculateButton, spanElement);


//

var i = 1;
var l = 4;
var j = 1;
var k = 40;

var answers = [
    (i + (i * (l - k) * 0.01) - ((i + (i * (l - 2) * 0.01)) * (j - 1) * 0.09))
];

console.log('Your answer is (' + answers[0] + ')');