Spaces:
Running

wtf / index.html
fgregergr's picture
skapa kalkylatorverktyg webbplats fokus på Sverige matha problem. Denna webbplats använde fullt svenskt språk. främst fokuserad stationär användare och fullt lyhörd. - Initial Deployment
8435628 verified
Raw History Blame Contribute Delete
21.2 kB
<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Svensk Matematikkalkylator</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.calculator-btn {
transition: all 0.2s ease;
}
.calculator-btn:hover {
transform: scale(1.05);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.calculator-btn:active {
transform: scale(0.98);
}
.history-item:hover {
background-color: #f3f4f6;
cursor: pointer;
}
@media (max-width: 768px) {
.calculator-grid {
grid-template-columns: repeat(4, 1fr);
gap: 0.5rem;
}
}
</style>
</head>
<body class="bg-gray-100 min-h-screen font-sans">
<div class="container mx-auto px-4 py-8 max-w-4xl">
<header class="text-center mb-8">
<h1 class="text-4xl font-bold text-blue-800 mb-2">Svensk Matematikkalkylator</h1>
<p class="text-lg text-gray-600">Ditt verktyg för svenska matematikproblem</p>
</header>
<div class="bg-white rounded-xl shadow-lg overflow-hidden">
<!-- Calculator display -->
<div class="p-4 bg-gray-50 border-b">
<div class="flex justify-between items-center mb-2">
<div class="text-sm text-gray-500" id="history-display"></div>
<button id="clear-history" class="text-blue-600 hover:text-blue-800 text-sm">
<i class="fas fa-trash-alt mr-1"></i>Rensa historik
</button>
</div>
<input type="text" id="display" class="w-full text-right text-3xl font-semibold bg-transparent outline-none" readonly>
<div id="result" class="w-full text-right text-xl text-gray-500 mt-1"></div>
</div>
<!-- Calculator body -->
<div class="p-4">
<div class="grid calculator-grid grid-cols-5 gap-2">
<!-- First row -->
<button onclick="addToDisplay('(')" class="calculator-btn bg-gray-200 hover:bg-gray-300 text-gray-800 font-bold py-3 px-4 rounded-lg">
(
</button>
<button onclick="addToDisplay(')')" class="calculator-btn bg-gray-200 hover:bg-gray-300 text-gray-800 font-bold py-3 px-4 rounded-lg">
)
</button>
<button onclick="addToDisplay('%')" class="calculator-btn bg-gray-200 hover:bg-gray-300 text-gray-800 font-bold py-3 px-4 rounded-lg">
%
</button>
<button onclick="clearDisplay()" class="calculator-btn bg-red-100 hover:bg-red-200 text-red-700 font-bold py-3 px-4 rounded-lg col-span-2">
<i class="fas fa-eraser mr-1"></i>Rensa
</button>
<!-- Second row -->
<button onclick="addToDisplay('7')" class="calculator-btn bg-white hover:bg-gray-100 text-gray-800 font-bold py-3 px-4 rounded-lg border border-gray-200">
7
</button>
<button onclick="addToDisplay('8')" class="calculator-btn bg-white hover:bg-gray-100 text-gray-800 font-bold py-3 px-4 rounded-lg border border-gray-200">
8
</button>
<button onclick="addToDisplay('9')" class="calculator-btn bg-white hover:bg-gray-100 text-gray-800 font-bold py-3 px-4 rounded-lg border border-gray-200">
9
</button>
<button onclick="addToDisplay('/')" class="calculator-btn bg-blue-100 hover:bg-blue-200 text-blue-700 font-bold py-3 px-4 rounded-lg">
÷
</button>
<button onclick="addToDisplay('Math.sqrt(')" class="calculator-btn bg-blue-100 hover:bg-blue-200 text-blue-700 font-bold py-3 px-4 rounded-lg">
√
</button>
<!-- Third row -->
<button onclick="addToDisplay('4')" class="calculator-btn bg-white hover:bg-gray-100 text-gray-800 font-bold py-3 px-4 rounded-lg border border-gray-200">
4
</button>
<button onclick="addToDisplay('5')" class="calculator-btn bg-white hover:bg-gray-100 text-gray-800 font-bold py-3 px-4 rounded-lg border border-gray-200">
5
</button>
<button onclick="addToDisplay('6')" class="calculator-btn bg-white hover:bg-gray-100 text-gray-800 font-bold py-3 px-4 rounded-lg border border-gray-200">
6
</button>
<button onclick="addToDisplay('*')" class="calculator-btn bg-blue-100 hover:bg-blue-200 text-blue-700 font-bold py-3 px-4 rounded-lg">
×
</button>
<button onclick="addToDisplay('Math.pow(')" class="calculator-btn bg-blue-100 hover:bg-blue-200 text-blue-700 font-bold py-3 px-4 rounded-lg">
x^y
</button>
<!-- Fourth row -->
<button onclick="addToDisplay('1')" class="calculator-btn bg-white hover:bg-gray-100 text-gray-800 font-bold py-3 px-4 rounded-lg border border-gray-200">
1
</button>
<button onclick="addToDisplay('2')" class="calculator-btn bg-white hover:bg-gray-100 text-gray-800 font-bold py-3 px-4 rounded-lg border border-gray-200">
2
</button>
<button onclick="addToDisplay('3')" class="calculator-btn bg-white hover:bg-gray-100 text-gray-800 font-bold py-3 px-4 rounded-lg border border-gray-200">
3
</button>
<button onclick="addToDisplay('-')" class="calculator-btn bg-blue-100 hover:bg-blue-200 text-blue-700 font-bold py-3 px-4 rounded-lg">
-
</button>
<button onclick="addToDisplay('Math.PI')" class="calculator-btn bg-blue-100 hover:bg-blue-200 text-blue-700 font-bold py-3 px-4 rounded-lg">
π
</button>
<!-- Fifth row -->
<button onclick="addToDisplay('0')" class="calculator-btn bg-white hover:bg-gray-100 text-gray-800 font-bold py-3 px-4 rounded-lg border border-gray-200">
0
</button>
<button onclick="addToDisplay('.')" class="calculator-btn bg-white hover:bg-gray-100 text-gray-800 font-bold py-3 px-4 rounded-lg border border-gray-200">
,
</button>
<button onclick="calculate()" class="calculator-btn bg-green-500 hover:bg-green-600 text-white font-bold py-3 px-4 rounded-lg col-span-2">
<i class="fas fa-equals mr-1"></i>Beräkna
</button>
<button onclick="addToDisplay('+')" class="calculator-btn bg-blue-100 hover:bg-blue-200 text-blue-700 font-bold py-3 px-4 rounded-lg">
+
</button>
</div>
</div>
</div>
<!-- History section -->
<div class="mt-8 bg-white rounded-xl shadow-lg overflow-hidden">
<div class="p-4 bg-gray-50 border-b">
<h2 class="text-xl font-semibold text-gray-800 flex items-center">
<i class="fas fa-history mr-2 text-blue-600"></i>Beräkningshistorik
</h2>
</div>
<div class="p-4">
<ul id="history-list" class="divide-y divide-gray-200">
<!-- History items will be added here -->
</ul>
</div>
</div>
<!-- Swedish math tools section -->
<div class="mt-8 grid grid-cols-1 md:grid-cols-2 gap-4">
<div class="bg-white rounded-xl shadow-lg overflow-hidden">
<div class="p-4 bg-gray-50 border-b">
<h2 class="text-xl font-semibold text-gray-800 flex items-center">
<i class="fas fa-ruler-combined mr-2 text-blue-600"></i>Måttenheter
</h2>
</div>
<div class="p-4">
<div class="mb-4">
<label class="block text-gray-700 mb-2">Längd</label>
<div class="grid grid-cols-2 gap-2">
<input type="number" id="length-value" class="border rounded-lg p-2" placeholder="Värde">
<select id="length-unit" class="border rounded-lg p-2">
<option value="mm">Millimeter</option>
<option value="cm">Centimeter</option>
<option value="dm">Decimeter</option>
<option value="m" selected>Meter</option>
<option value="km">Kilometer</option>
<option value="in">Tum</option>
<option value="ft">Fot</option>
</select>
</div>
<button onclick="convertLength()" class="mt-2 w-full bg-blue-500 hover:bg-blue-600 text-white py-2 rounded-lg">
Konvertera
</button>
<div id="length-result" class="mt-2 p-2 bg-gray-50 rounded-lg text-sm"></div>
</div>
</div>
</div>
<div class="bg-white rounded-xl shadow-lg overflow-hidden">
<div class="p-4 bg-gray-50 border-b">
<h2 class="text-xl font-semibold text-gray-800 flex items-center">
<i class="fas fa-calculator mr-2 text-blue-600"></i>Geometri
</h2>
</div>
<div class="p-4">
<div class="mb-4">
<label class="block text-gray-700 mb-2">Area av cirkel</label>
<div class="grid grid-cols-2 gap-2">
<input type="number" id="circle-radius" class="border rounded-lg p-2" placeholder="Radie">
<select id="circle-unit" class="border rounded-lg p-2">
<option value="mm">mm</option>
<option value="cm">cm</option>
<option value="m" selected>m</option>
</select>
</div>
<button onclick="calculateCircleArea()" class="mt-2 w-full bg-blue-500 hover:bg-blue-600 text-white py-2 rounded-lg">
Beräkna area
</button>
<div id="circle-result" class="mt-2 p-2 bg-gray-50 rounded-lg text-sm"></div>
</div>
</div>
</div>
</div>
<footer class="mt-12 text-center text-gray-600 text-sm">
<p>© 2023 Svensk Matematikkalkylator | Utvecklad för svenska matematikproblem</p>
</footer>
</div>
<script>
// Calculator functionality
let calculationHistory = [];
function addToDisplay(value) {
const display = document.getElementById('display');
display.value += value;
}
function clearDisplay() {
document.getElementById('display').value = '';
document.getElementById('result').textContent = '';
}
function calculate() {
const display = document.getElementById('display');
const resultElement = document.getElementById('result');
try {
// Replace Swedish decimal comma with dot for calculation
let expression = display.value.replace(/,/g, '.');
// Special handling for percentage
expression = expression.replace(/(\d+)%/g, '($1/100)');
// Evaluate the expression
const calculatedResult = eval(expression);
// Format the result with Swedish decimal comma
const formattedResult = calculatedResult.toString().replace(/\./g, ',');
resultElement.textContent = '= ' + formattedResult;
// Add to history
const historyItem = {
expression: display.value,
result: formattedResult
};
calculationHistory.unshift(historyItem);
updateHistory();
// Update history display
document.getElementById('history-display').textContent = display.value;
// Clear the display for new input
display.value = '';
} catch (error) {
resultElement.textContent = 'Fel: Ogiltigt uttryck';
resultElement.classList.add('text-red-500');
setTimeout(() => {
resultElement.textContent = '';
resultElement.classList.remove('text-red-500');
}, 2000);
}
}
function updateHistory() {
const historyList = document.getElementById('history-list');
historyList.innerHTML = '';
// Limit to 10 most recent items
const recentHistory = calculationHistory.slice(0, 10);
recentHistory.forEach(item => {
const li = document.createElement('li');
li.className = 'py-2 history-item';
li.innerHTML = `
<div class="flex justify-between">
<span class="text-gray-700">${item.expression}</span>
<span class="font-semibold text-blue-600">= ${item.result}</span>
</div>
`;
li.addEventListener('click', () => {
document.getElementById('display').value = item.expression;
document.getElementById('result').textContent = '= ' + item.result;
});
historyList.appendChild(li);
});
}
document.getElementById('clear-history').addEventListener('click', () => {
calculationHistory = [];
updateHistory();
document.getElementById('history-display').textContent = '';
});
// Unit conversion functionality
function convertLength() {
const value = parseFloat(document.getElementById('length-value').value);
const unit = document.getElementById('length-unit').value;
if (isNaN(value)) {
alert('Ange ett giltigt nummer');
return;
}
let results = [];
// Convert to all units
let mm, cm, dm, m, km, inches, feet;
switch (unit) {
case 'mm':
mm = value;
cm = value / 10;
dm = value / 100;
m = value / 1000;
km = value / 1000000;
inches = value / 25.4;
feet = value / 304.8;
break;
case 'cm':
mm = value * 10;
cm = value;
dm = value / 10;
m = value / 100;
km = value / 100000;
inches = value / 2.54;
feet = value / 30.48;
break;
case 'dm':
mm = value * 100;
cm = value * 10;
dm = value;
m = value / 10;
km = value / 10000;
inches = value * 3.937;
feet = value / 3.048;
break;
case 'm':
mm = value * 1000;
cm = value * 100;
dm = value * 10;
m = value;
km = value / 1000;
inches = value * 39.37;
feet = value * 3.281;
break;
case 'km':
mm = value * 1000000;
cm = value * 100000;
dm = value * 10000;
m = value * 1000;
km = value;
inches = value * 39370;
feet = value * 3281;
break;
case 'in':
mm = value * 25.4;
cm = value * 2.54;
dm = value * 0.254;
m = value * 0.0254;
km = value * 0.0000254;
inches = value;
feet = value / 12;
break;
case 'ft':
mm = value * 304.8;
cm = value * 30.48;
dm = value * 3.048;
m = value * 0.3048;
km = value * 0.0003048;
inches = value * 12;
feet = value;
break;
}
// Format results with Swedish decimal commas
const format = num => num.toFixed(2).replace(/\./g, ',');
document.getElementById('length-result').innerHTML = `
<p><strong>Millimeter:</strong> ${format(mm)} mm</p>
<p><strong>Centimeter:</strong> ${format(cm)} cm</p>
<p><strong>Decimeter:</strong> ${format(dm)} dm</p>
<p><strong>Meter:</strong> ${format(m)} m</p>
<p><strong>Kilometer:</strong> ${format(km)} km</p>
<p><strong>Tum:</strong> ${format(inches)} in</p>
<p><strong>Fot:</strong> ${format(feet)} ft</p>
`;
}
// Geometry calculations
function calculateCircleArea() {
const radius = parseFloat(document.getElementById('circle-radius').value);
const unit = document.getElementById('circle-unit').value;
if (isNaN(radius) || radius <= 0) {
alert('Ange en giltig positiv radie');
return;
}
const area = Math.PI * Math.pow(radius, 2);
const circumference = 2 * Math.PI * radius;
document.getElementById('circle-result').innerHTML = `
<p><strong>Area:</strong> ${area.toFixed(2).replace(/\./g, ',')} ${unit}²</p>
<p><strong>Omkrets:</strong> ${circumference.toFixed(2).replace(/\./g, ',')} ${unit}</p>
`;
}
// Keyboard support
document.addEventListener('keydown', function(event) {
const key = event.key;
// Allow numbers and basic operators
if (/[0-9+\-*/.%()=]/.test(key)) {
if (key === '=') {
if (event.shiftKey) {
addToDisplay('+');
} else {
calculate();
}
} else {
addToDisplay(key);
}
} else if (key === 'Enter') {
calculate();
} else if (key === 'Backspace') {
const display = document.getElementById('display');
display.value = display.value.slice(0, -1);
} else if (key === 'Escape') {
clearDisplay();
}
});
</script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=fgregergr/wtf" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>