Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
adc41a6
Import Bootstrap
michael-mcmasters Nov 6, 2020
dd98d42
Create and import styles.css
michael-mcmasters Nov 6, 2020
4aed214
Set layout with Bootstrap
michael-mcmasters Nov 6, 2020
3285628
Create layout with pure CSS and no Bootstrap
michael-mcmasters Nov 6, 2020
1fd7e1c
Create second row
michael-mcmasters Nov 6, 2020
c8c9e44
Refactor button margins to simplify CSS
michael-mcmasters Nov 6, 2020
1a082eb
Set button padding to font-size. Replace <button> text with numbers a…
michael-mcmasters Nov 6, 2020
6aaee94
Create "Standard | Scientific" a tags
michael-mcmasters Nov 6, 2020
e8a62d4
Rename <title>
michael-mcmasters Nov 6, 2020
18b4083
Set button background colors
michael-mcmasters Nov 6, 2020
3b3ef75
Give buttons hover effect
michael-mcmasters Nov 6, 2020
770a94d
Change border color
michael-mcmasters Nov 6, 2020
cb6a025
Set <a> tag colors
michael-mcmasters Nov 6, 2020
d2411ee
Remove row class because it is unused
michael-mcmasters Nov 6, 2020
306f925
Create and style input field
michael-mcmasters Nov 6, 2020
2ae3150
Replaced symbols with &symbols
michael-mcmasters Nov 6, 2020
b252de0
Make decimal bold and increase url font-size
michael-mcmasters Nov 6, 2020
32941c7
Add <p> tag to each row with Javascript
michael-mcmasters Nov 6, 2020
e7bc311
Fill for Scientific buttons
michael-mcmasters Nov 6, 2020
cd4085f
Use Javascript to enable/disable Scientific calculator
michael-mcmasters Nov 7, 2020
970c369
Renamed Javascript file
michael-mcmasters Nov 7, 2020
908ca4e
Add event listener for when user readjusts window size
michael-mcmasters Nov 7, 2020
a3fd48c
Make it so scientific buttons move to bottom of calculator if the scr…
michael-mcmasters Nov 7, 2020
09cca6d
Make buttons responsive with CSS and Javascript
michael-mcmasters Nov 7, 2020
e7fd69a
Give Standard and Scientific buttons IDs
michael-mcmasters Nov 7, 2020
799691b
Give event listeners to both buttons
michael-mcmasters Nov 7, 2020
c16a902
Clean up functions and comments
michael-mcmasters Nov 9, 2020
0021143
Added scientific buttons to structure with a default of display: none
michael-mcmasters Nov 9, 2020
4f17c2d
Set display to block with Javascript for some buttons
michael-mcmasters Nov 9, 2020
8028a0c
Enable and disable scientific buttons
michael-mcmasters Nov 9, 2020
c943a02
Combine enable and disable into one function, toggle
michael-mcmasters Nov 9, 2020
1f0030d
Make Scientific buttons responsive with Javascript. Add/remove correc…
michael-mcmasters Nov 9, 2020
f6e0a20
Remove deprecated script
michael-mcmasters Nov 9, 2020
472dc91
Set input field's width to 100%
michael-mcmasters Nov 9, 2020
a241962
Set correct color for scientific buttons
michael-mcmasters Nov 9, 2020
926601f
Create two classes for Rad and Deg buttons
michael-mcmasters Nov 9, 2020
4710060
Combine Rad and Deg into one button
michael-mcmasters Nov 9, 2020
c10a738
Add color to Rad | Deg button
michael-mcmasters Nov 9, 2020
451dd86
Make Rad | Deg button work when buttons are at bottom of calculator
michael-mcmasters Nov 9, 2020
3c57b45
Make Rad | Deg button responsive
michael-mcmasters Nov 9, 2020
c055e39
Fix padding for Rad and Deg button when window width is small
michael-mcmasters Nov 16, 2020
c9c2f2d
Replace button text with HTML Unicode symbols
michael-mcmasters Nov 16, 2020
faf5c42
Change font size of symbols. Set buttons to use rem padding instead o…
michael-mcmasters Nov 16, 2020
8ad1194
Fix sizing
michael-mcmasters Nov 16, 2020
4c88367
Disable scientific buttons on start-up
michael-mcmasters Nov 16, 2020
ec6059c
Git rid of d-flex class and put display: rlex in .row instead
michael-mcmasters Nov 16, 2020
efa6f73
Fix width for everything except input box
michael-mcmasters Nov 16, 2020
6e0d054
Use media queries to change input width
michael-mcmasters Nov 17, 2020
f4559f2
Add another media query for input box
michael-mcmasters Nov 17, 2020
83f0eb3
Get input width to be correct width for all sizes and layouts
michael-mcmasters Nov 17, 2020
7518b6d
Clean up
michael-mcmasters Nov 17, 2020
13a56c3
Add margin left to bottom scientific buttons
michael-mcmasters Nov 17, 2020
a55aaac
Create CSS id for standard / scientific buttons
michael-mcmasters Nov 17, 2020
d9b8ba6
Change color of standard / scientific button depending on which is ac…
michael-mcmasters Nov 17, 2020
53d7860
Fix margin for bottom scientific buttons
michael-mcmasters Nov 17, 2020
e6eb4fc
Remove border when button is clicked
michael-mcmasters Nov 17, 2020
45845ef
Fix padding around elements inside calculator
michael-mcmasters Nov 17, 2020
e4ce623
Fix width for rad / deg button when window is small
michael-mcmasters Nov 17, 2020
28048d7
Make color on hover work again
michael-mcmasters Nov 17, 2020
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
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:5500",
"webRoot": "${workspaceFolder}"
}
]
}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
118 changes: 118 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<!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="./styles.css">

<title>Calculator</title>
</head>


<body class="d-flex justify-center">




<div id="calc-container" class="border squircle">

<div class="url-row d-flex margin-3">
<a id="standard-button">Standard</a>
<span>|</span>
<a id="scientific-button">Scientific</a>
</div>

<input type="text" class="border squircle">

<div class="row">
<div class="scientific-btn-left">
<button class="rad-deg-button">
<span>Rad</span>
<span>|</span>
<span>Deg</span>
</button>
</div>
<button class="scientific-btn-left">x!</button>
<button>(</button>
<button>)</button>
<button>%</button>
<button>AC</button>
</div>

<div class="row">
<button class="scientific-btn-left btn-light-gray">Inv</button>
<button class="scientific-btn-left">sin</button>
<button class="scientific-btn-left">In</button>
<button class="btn-light-gray">7</button>
<button class="btn-light-gray">8</button>
<button class="btn-light-gray">9</button>
<button class="button-symbols">&divide;</button>
</div>
<div class="row ">
<button class="scientific-btn-left">&#960;</button>
<button class="scientific-btn-left">cos</button>
<button class="scientific-btn-left">log</button>
<button class="btn-light-gray">4</button>
<button class="btn-light-gray">5</button>
<button class="btn-light-gray">6</button>
<button class="button-symbols">&times;</button>
</div>
<div class="row ">
<button class="scientific-btn-left">e</button>
<button class="scientific-btn-left">tan</button>
<button class="scientific-btn-left">&#10003</button>
<button class="btn-light-gray">1</button>
<button class="btn-light-gray">2</button>
<button class="btn-light-gray">3</button>
<button class="button-symbols">&minus;</button>
</div>
<div class="row ">
<button class="scientific-btn-left">Ans</button>
<button class="scientific-btn-left">EXP</button>
<button class="scientific-btn-left">X<sup>y</sup></button>
<button class="btn-light-gray">0</button>
<button class="btn-light-gray" style="font-weight: bold;">.</button>
<button class="btn-blue">=</button>
<button class="button-symbols">&plus;</button>
</div>

<div class="scientific-btn-bottom">
<button class="rad-deg-button">
<span>Rad</span>
<span>|</span>
<span>Deg</span>
</button>
<button>x!</button>
</div>

<div class="scientific-btn-bottom">
<button>Inv</button>
<button>sin</button>
<button>In</button>
</div>

<div class="scientific-btn-bottom">
<button>&#960;</button>
<button>cos</button>
<button>log</button>
</div>

<div class="scientific-btn-bottom">
<button>e</button>
<button>tan</button>
<button>&#10003</button>
</div>

<div class="scientific-btn-bottom">
<button>Ans</button>
<button>EXP</button>
<button>X<sup>y</sup></button>
</div>
</div>

<script src="scientific-calculator-enabler.js"></script>
</body>

</html>
63 changes: 63 additions & 0 deletions scientific-calculator-enabler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// By default, scientific buttons have a class set to display: none.
// This script enables/disables them depending on the button pressed and the screen width.

let scientificButtonsEnabled = false;
let standardButton = document.getElementById("standard-button");
let scientificButton = document.getElementById("scientific-button");

standardButton.addEventListener("click", () => {
disableScientificButtons();
setActiveButtonColor(standardButton, scientificButton);
scientificButtonsEnabled = false;
});

scientificButton.addEventListener("click", () => {
enableScientificButtons();
setActiveButtonColor(scientificButton, standardButton);
scientificButtonsEnabled = true;
});

// Responsive: Moves buttons to the left or bottom of calculator depending on screen width.
window.addEventListener("resize", () => {
if (scientificButtonsEnabled) {
enableScientificButtons();
}
});

function disableScientificButtons() {
setDisplayToNone(document.querySelectorAll(".scientific-btn-left"));
setDisplayToNone(document.querySelectorAll(".scientific-btn-bottom"));
}

function setDisplayToNone(buttons) {
for (let i = 0; i < buttons.length; i++) {
buttons[i].style.display = "none";
}
}

// Enables buttons on the left or bottom depending on screen width.
function enableScientificButtons() {
disableScientificButtons(); // Edge Case: Disable any existing buttons so left and bottom buttons are never active at the same time.
let className = getClassToActivate();
let scientificButtons = document.querySelectorAll(className);
for (let i = 0; i < scientificButtons.length; i++) {
scientificButtons[i].style.display = "block";
}
}

function getClassToActivate() {
if (document.body.clientWidth < 1105) {
return ".scientific-btn-bottom";
} else {
return ".scientific-btn-left";
}
}

// According to the mockup, the active button is blue with an underline and the deactive button is black.
function setActiveButtonColor(activeButton, disactiveButton) {
activeButton.style.color = "blue";
activeButton.style["text-decoration"] = "underline";

disactiveButton.style.color = "black";
disactiveButton.style["text-decoration"] = "none";
}
172 changes: 172 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/**** Shared Styles ****/

.margin-3 {
margin: 0.3rem;
}

.d-flex {
display: flex;
}

.justify-center {
justify-content: center;
}

.border {
border: 1px solid rgb(223, 225, 229);
}

.squircle {
border-radius: 10px;
}

/* a {
color: blue;
}

a:hover {
color: teal;
}

a:visited {
color: purple;
} */

#standard-button {
color: blue;
text-decoration: underline;
}

#standard-button:hover {
color: rgb(197, 197, 0) !important;
cursor: pointer;
}

#scientific-button {
color: black;
}

#scientific-button:hover {
color: rgb(197, 197, 0) !important;
cursor: pointer;
}

#calc-container {
width: fit-content;
padding: 1rem;
}

.url-row > * {
margin-right: 10px;
font-size: 19px;
}

.row {
display: flex;
}

input {
margin: 0.7rem 0.3rem;
width: 94%;
height: 1.7em;
font-size: 40px;
text-align: right;
}

button {
border-radius: 10px;
background-color: rgb(247, 140, 140);
border: none;
outline: none;
font-size: 19px;
width: 7rem;
height: 3rem;
margin: 0.3rem;
background-color: rgb(223, 225, 229);
}

/* Sometimes the HTML unicode size is small. This makes it larger */
.button-symbols {
font-size: 24px;
}

.rad-deg-button {
width: 14.6rem;
color: rgb(140, 142, 145);
}

.rad-deg-button > * {
padding: 1.2rem;
}

.rad-deg-button :first-child {
color: black;
}

.btn-light-gray {
background-color: rgb(241, 243, 244);
}

.btn-blue {
background-color: rgb(66, 133, 244);
color: white;
font-weight: bold;
}

button:hover {
cursor: pointer;
background-color: rgb(215, 217, 221);
}

button.btn-light-gray:hover {
background-color: rgb(232, 234, 235);
}
button.btn-blue:hover {
background-color: rgb(77, 139, 241);
}

/* Hidden by default. Enabled by Javascript. */
.scientific-btn-left {
display: none;
}

/* Hidden by default. Enabled by Javascript. */
.scientific-btn-bottom {
display: none;
}

@media (min-width: 1105px) {
input {
width: 98.7%;
}
}

@media (max-width: 1120px) {
.rad-deg-button {
width: 15rem;
}
}

@media (max-width: 542px) {
input {
width: 97%;
margin-right: 0;
padding-right: 0;
}

button {
width: 25%;
}

.scientific-btn-bottom {
margin-left: 0;
}

.rad-deg-button {
width: 53%;
}

.rad-deg-button > * {
padding: 0.6rem;
}
}