Word Problem Calculator

A simple word problem calculator

目前為 2024-09-21 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Word Problem Calculator
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  A simple word problem calculator
// @author       Your Name
// @match        https://easybridge-dashboard-web.savvaseasybridge.com/dashboard/student?ssoLogin=true
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function wordProblemCalculator() {
        const problem = prompt("Enter a word problem (e.g., 'Julio has 4 footballs to put in 2 boxes. He will put the same number in each box. How many footballs in each box?'):").toLowerCase();

        // Extract all numbers from the input
        const numbers = problem.match(/\d+/g);
        
        // Check if we have enough numbers
        if (!numbers || numbers.length < 2) {
            alert("Could not find enough numbers in the problem.");
            return;
        }

        let result;

        // Handle specific case for equal distribution
        if (problem.includes("put the same number in each box") || problem.includes("how many in each box")) {
            const totalFootballs = parseFloat(numbers[0]);
            const totalBoxes = parseFloat(numbers[1]);
            result = totalFootballs / totalBoxes; // Division
        } 
        // Handle multiplication
        else if (problem.includes("times") || problem.includes("multiplied by") || problem.includes("x")) {
            const num1 = parseFloat(numbers[0]);
            const num2 = parseFloat(numbers[1]);
            result = num1 * num2; // Multiplication
        } 
        // Handle addition
        else if (problem.includes("plus") || problem.includes("added to") || problem.includes("+")) {
            const num1 = parseFloat(numbers[0]);
            const num2 = parseFloat(numbers[1]);
            result = num1 + num2; // Addition
        } 
        // Handle subtraction
        else if (problem.includes("minus") || problem.includes("-") || problem.includes("gave away") || problem.includes("left")) {
            const total = parseFloat(numbers[0]);
            const givenAway = parseFloat(numbers[1]);
            result = total - givenAway; // Subtraction
        } 
        // Handle division
        else if (problem.includes("divided by") || problem.includes("equals") || problem.includes("=")) {
            const num1 = parseFloat(numbers[0]);
            const num2 = parseFloat(numbers[1]);
            result = num2 / num1; // Division
        } 
        else {
            alert("Could not understand the word problem.");
            return;
        }

        alert(`The result of the problem is: ${result}`);
    }

    // Run the calculator
    wordProblemCalculator();
})();