Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Square Root Calculator is added #2198

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 25 additions & 0 deletions Square Root/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>

<head>
<link rel="stylesheet" type="text/css" href="./style.css">
<title>Square Root Calculator</title>
</head>

<body>
<div class="container">
<h1>Square Root Calculator</h1>
<input type="number" id="numberInput" placeholder="Enter a number">

<br>

<input type="number" id="precisionInput" placeholder="Enter precision">
<button onclick="calculateSquareRoot()">Calculate Square Root</button>

<p id="result"></p>
</div>

<script src="./script.js"></script>
</body>

</html>
10 changes: 10 additions & 0 deletions Square Root/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"manifest_version": 3,
"name": "Square Root",
"version": "1.0",
"description": "Simply square root of a number",
"action": {
"default_popup": "index.html"
},
"permissions": []
}
17 changes: 17 additions & 0 deletions Square Root/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function calculateSquareRoot() {
// Fetching the input values: number and precision
const number = parseFloat(document.getElementById('numberInput').value);
const precision = parseInt(document.getElementById('precisionInput').value);

// Checking if the inputs are valid numbers
if (isNaN(number) || isNaN(precision)) {
document.getElementById('result').innerHTML = 'Please enter a valid number and precision.';
return;
}

// Calculating square root and limiting decimal places using toFixed()
const squareRoot = Math.sqrt(number).toFixed(precision);

// Displaying the result with the specified precision
document.getElementById('result').innerHTML = `The square root of ${number} up to ${precision} decimal places is: ${squareRoot}`;
}
50 changes: 50 additions & 0 deletions Square Root/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
html {
background-color: rgb(62, 62, 62);
}

body {
font-family: Arial, sans-serif;
text-align: center;
margin-top: 50px;
background-color: transparent;
}

h1 {
color: #333;
}

.container {
width: 50%;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

input[type="number"] {
padding: 8px;
margin: 10px;
width: 200px;
font-size: 16px;
}

button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
}

button:hover {
background-color: #45a049;
}

#result {
margin-top: 20px;
font-size: 18px;
color: #333;
}
Loading