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
Tag: Reverted
(Blanked the page)
Tags: Blanking Manual revert
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
// Get the parent element
var parentElement = document.getElementById('simple-calc__container');


// Get the span elements to be replaced
var spanElements = parentElement.getElementsByTagName('span');
// Convert spanElements to an array
var spanArray = Array.from(spanElements);
// Loop through each span element
spanArray.slice(0, 3).forEach(function (spanElement, index) {
  // Create the input element
  var inputElement = document.createElement('input');
  inputElement.type = 'text';
  inputElement.placeholder = 'Enter a value';
  inputElement.id = 'simple-calc__input' + (index + 1); // Assign ID to the input element
  // Replace the span element with the input element
  spanElement.parentNode.replaceChild(inputElement, spanElement);
});
// Get the span element to be replaced with the button
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;
  // Calculate k based on the seed value
  var seedValue = parseFloat(document.getElementById('simple-calc__seed').textContent);
  // Output the results
  console.log('i = ' + i);
  console.log('l = ' + l);
  console.log('j = ' + j);
  console.log('seedValue = '+ seedValue);
  // You can perform further calculations or actions based on the input values here
var answer = (1 + (1 * (26 - seedValue) * 0.01) - ((1 + (1 * (26 - 2) * 0.01)) * (3 - 1) * 0.09));
console.log('Your answer is (' + answer + ')');
});
// Replace the span element with the button
spanElement.parentNode.replaceChild(calculateButton, spanElement);

Latest revision as of 18:28, 12 August 2025