Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

calculator updates pps#1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
hariraj27 wants to merge1 commit intocl-lw:main
base:main
Choose a base branch
Loading
fromhariraj27:hariraj-pps
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletionsprojects/simple calculator/index.html
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Calculator</title>
</head>
<body>
<div class="calculator">
<h1><strong>CALCULATOR</strong></h1>
<div class="display" id="display">0</div>
<div class="buttons">
<button class="operator" onclick="appendToDisplay('/')">/</button>
<button class="number" onclick="appendToDisplay('7')">7</button>
<button class="number" onclick="appendToDisplay('8')">8</button>
<button class="number" onclick="appendToDisplay('9')">9</button>
<button class="operator" onclick="appendToDisplay('*')">*</button>
<button class="number" onclick="appendToDisplay('4')">4</button>
<button class="number" onclick="appendToDisplay('5')">5</button>
<button class="number" onclick="appendToDisplay('6')">6</button>
<button class="operator" onclick="appendToDisplay('-')">-</button>
<button class="number" onclick="appendToDisplay('1')">1</button>
<button class="number" onclick="appendToDisplay('2')">2</button>
<button class="number" onclick="appendToDisplay('3')">3</button>
<button class="operator" onclick="appendToDisplay('+')">+</button>
<button class="number" onclick="appendToDisplay('0')">0</button>
<button class="operator" onclick="appendToDisplay('.')">.</button>
<button class="equals" onclick="calculate()">=</button>
<button class="reset" onclick="clearDisplay()">Reset</button>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
58 changes: 58 additions & 0 deletionsprojects/simple calculator/script.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
let display = document.getElementById('display');
let currentInput = '';

function appendToDisplay(value) {
currentInput += value;
display.textContent = currentInput;
}

function clearDisplay() {
currentInput = '';
display.textContent = '0';
}

function calculate() {
try {
currentInput = eval(currentInput).toString();
display.textContent = currentInput;
} catch (error) {
display.textContent = 'Error';
}
}
document.addEventListener("DOMContentLoaded", function () {
let display = document.getElementById('display');
let currentInput = '';

function appendToDisplay(value) {
currentInput += value;
display.textContent = currentInput;
}

function clearDisplay() {
currentInput = '';
display.textContent = '0';
}

function calculate() {
try {
const result = Function('"use strict";return (' + currentInput + ')')();
currentInput = result.toString();
display.textContent = currentInput;
} catch (error) {
display.textContent = 'Error';
}
}

// Add event listeners for each button
document.querySelectorAll('.number').forEach(button => {
button.addEventListener('click', () => appendToDisplay(button.textContent));
});

document.querySelectorAll('.operator').forEach(button => {
button.addEventListener('click', () => appendToDisplay(button.textContent));
});

document.querySelector('.equals').addEventListener('click', calculate);

document.querySelector('.reset').addEventListener('click', clearDisplay);
});
70 changes: 70 additions & 0 deletionsprojects/simple calculator/style.css
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
body {
margin: 0;
font-family: Arial, sans-serif;
background-image: url('https://images.unsplash.com/photo-1625225233840-695456021cde?q=80&w=1000&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8M3x8Y2FsY3VsYXRvcnxlbnwwfHwwfHx8MA%3D%3D');
background-size: cover;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
color: white;
}

h1 {
margin-bottom: 20px;
}

.calculator {
background-color: rgba(0, 0, 0, 0.5);
border-radius: 10px;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

.display {
padding: 10px;
margin-bottom: 10px;
text-align: right;
font-size: 2em;
background-color: rgba(255, 255, 255, 0.1);
border: none;
border-radius: 5px;
width: 100%;
box-sizing: border-box;
}

.buttons {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 10px;
}

button {
width: 100%;
padding: 15px;
font-size: 1.5em;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}

button:hover {
background-color: rgba(255, 255, 255, 0.1);
}

.number {
background-color: #3498db;
color: white;
}

.operator {
background-color: #e74c3c;
color: white;
}

.equals {
background-color: #2ecc71;
color: white;
}

[8]ページ先頭

©2009-2025 Movatter.jp