A simple word problem calculator
当前为
// ==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();
})();