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

(round to two decimal places and show gems)
No edit summary
Line 43: Line 43:


   // Calculate the answer based on the simplified equation
   // Calculate the answer based on the simplified equation
   var answer = +(i + (i * (l - seedValue) * 0.01) - ((i + (i * (l - 2) * 0.01)) * (j - 1) * 0.09).toFixed(2));
   var answer = i + (i * (l - seedValue) * 0.01) - ((i + (i * (l - 2) * 0.01)) * (j - 1) * 0.09).toFixed(2);


   // Output the answer
   // Output the answer

Revision as of 03:18, 25 October 2023

// Create the input elements and replace the corresponding span elements
for (var index = 1; index <= 3; index++) {
  var spanElement = document.getElementById('simple-calc__rinput' + index);

  // Create the input element
  var inputElement = document.createElement('input');
  inputElement.type = 'text';
  inputElement.placeholder = 'Enter a value';
  inputElement.id = 'simple-calc__input' + index;

  // 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('k = ' + seedValue);

  // Calculate the answer based on the simplified equation
  var answer = i + (i * (l - seedValue) * 0.01) - ((i + (i * (l - 2) * 0.01)) * (j - 1) * 0.09).toFixed(2);

  // Output the answer
  console.log('Your answer is (' + answer + ')');

  // Replace the answer element with the calculated answer
  var answerElement = document.getElementById('simple-calc__answer');
  answerElement.textContent = '₲' + answer;
});

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