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

User:LaluShi/common.js: Difference between revisions

From Growtopia Wiki
LaluShi (talk | contribs)
Created page with "function calculate() { // Get input values var num1 = parseFloat(document.getElementById('num1').value); var num2 = parseFloat(document.getElementById('num2').value); // Get selected operation var operation = document.getElementById('operation').value; // Perform calculation based on operation var result; switch(operation) { case 'addition': result = num1 + num2; break; case 'subtraction':..."
 
LaluShi (talk | contribs)
No edit summary
Line 1: Line 1:
function calculate() {
$(document).ready(function() {
     // Get input values
     // Check if we are on the page where we want to insert the XP calculation box
     var num1 = parseFloat(document.getElementById('num1').value);
     if (mw.config.get('wgCanonicalNamespace') === 'User_blog' && mw.config.get('wgAction') === 'view') {
    var num2 = parseFloat(document.getElementById('num2').value);
        // Create the HTML elements for the XP calculation box
   
        var xpCalculationBox = '<h2>XP Calculation</h2>' +
    // Get selected operation
            '<div>' +
    var operation = document.getElementById('operation').value;
            '  <label for="rValue">Enter the rarity (R):</label>' +
   
            ' <input type="number" id="rValue" min="0" step="1">' +
    // Perform calculation based on operation
             '  <button onclick="calculateXP()">Calculate XP</button>' +
    var result;
             '</div>' +
    switch(operation) {
            '<div>' +
        case 'addition':
             '  <p id="xpResult"></p>' +
             result = num1 + num2;
             '</div>';
             break;
          
        case 'subtraction':
        // Insert the XP calculation box into the page
             result = num1 - num2;
        $('.mw-parser-output').prepend(xpCalculationBox);
             break;
       
         case 'multiplication':
        // Function to calculate XP when the button is clicked
            result = num1 * num2;
        window.calculateXP = function() {
             break;
             // Get the value of R from the input field
        case 'division':
            var r = parseInt($('#rValue').val());
             result = num1 / num2;
           
             break;
             // Calculate E using the formula E = 1 + floor(R / 5)
        default:
             var e = 1 + Math.floor(r / 5);
             result = 'Invalid operation';
           
             // Display the result
            $('#xpResult').text("XP Earned: " + e);
        };
     }
     }
   
});
    // Display result
    document.getElementById('result').innerHTML = "Result: " + result;
}

Revision as of 21:19, 14 May 2024

$(document).ready(function() {
    // Check if we are on the page where we want to insert the XP calculation box
    if (mw.config.get('wgCanonicalNamespace') === 'User_blog' && mw.config.get('wgAction') === 'view') {
        // Create the HTML elements for the XP calculation box
        var xpCalculationBox = '<h2>XP Calculation</h2>' +
            '<div>' +
            '  <label for="rValue">Enter the rarity (R):</label>' +
            '  <input type="number" id="rValue" min="0" step="1">' +
            '  <button onclick="calculateXP()">Calculate XP</button>' +
            '</div>' +
            '<div>' +
            '  <p id="xpResult"></p>' +
            '</div>';
        
        // Insert the XP calculation box into the page
        $('.mw-parser-output').prepend(xpCalculationBox);
        
        // Function to calculate XP when the button is clicked
        window.calculateXP = function() {
            // Get the value of R from the input field
            var r = parseInt($('#rValue').val());
            
            // Calculate E using the formula E = 1 + floor(R / 5)
            var e = 1 + Math.floor(r / 5);
            
            // Display the result
            $('#xpResult').text("XP Earned: " + e);
        };
    }
});