// Function to perform basic arithmetic operations
function calculate(a, b, operator) {
switch (operator) {
case '+':
return a + b;
case '-':
return a - b;
case '*':
return a * b;
case '/':
return a / b;
default:
return 'Invalid operator';
}
}
// Example: Perform addition (10 + 5)
const result = calculate(10, 5, '+');
console.log('Calculator Result:', result);Simple Calculator
javascript
Related Posts
More content you might like
Code
How to Create a New MySQL User with Full Privileges
CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON *.* TO 'your_username'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;May 01, 2025
Read More Code
python
Configuring SQLAlchemy with PostgreSQL on Heroku: A Quick Guide
- When you provision a PostgreSQL database on Heroku, it sets an environment variable called
DATABASE_URLwith the connection string for your database. - This URI uses the format
postgres://.
- SQLAlchemy (especially when using the
psycopg2driver for PostgreSQL) requires the URI to be in the formatpostgresql+psycopg2://. - This prefix specifies the dialect (
postgresql) and the driver (psycopg2) explicitly, which SQLAlchemy uses to establish the connection.
Nov 08, 2024
Read More Code
php
How to Delete All WordPress Posts and Their Uploads Using a Custom PHP Script
- Backup: Make sure you have a backup of your database and uploads folder before running this script.
- Use on a staging site: Test it on a staging environment before running on a live site, as it will permanently delete all posts and their uploads.
This script will ensure that both the posts and their associated media files are removed from the WordPress database and the filesystem.
Oct 25, 2024
Read More Code
php
How To enable all error debugging in PHP
No preview available for this content.
Oct 25, 2024
Read MoreDiscussion 0
Please sign in to join the discussion.
No comments yet. Be the first to share your thoughts!