Skip to content

updated calc logic #17

Open
brauni18 wants to merge 4 commits into
ColmanDevClubORG:mainfrom
brauni18:main
Open

updated calc logic #17
brauni18 wants to merge 4 commits into
ColmanDevClubORG:mainfrom
brauni18:main

Conversation

@brauni18

@brauni18 brauni18 commented Dec 4, 2025

Copy link
Copy Markdown

No description provided.

@Tamir198 Tamir198 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey left you come comments

Comment thread script.js
@@ -0,0 +1,74 @@
const numbers = document.querySelectorAll(".number");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good practice here to get all of the elements into 1 variable

Comment thread script.js
});
});

const addButton = document.getElementById("add");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should place all of your variables on top of your file

Comment thread script.js
addButton.addEventListener("click", () => {
display.textContent += "+";
});
subtractButton.addEventListener("click", () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you think of a way to add event listener too all of your operators? just like you did above

Comment thread script.js
display.textContent += "-";
});
multiplyButton.addEventListener("click", () => {
display.textContent += "*";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Save your strings into constant variables

Comment thread script.js
equalsButton.addEventListener("click", () => {

const expression = display.textContent;
const parts = expression.split(/([+\-*/])/);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Save the regex inside a variable

Comment thread script.js

if(part == "*") {
const prevNumber = parseFloat(parts[i - 1]);
const nextNumber = parseFloat(parts[i + 1]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should check that this it not NAN

Comment thread script.js
const prevNumber = parseFloat(parts[i - 1]);
const nextNumber = parseFloat(parts[i + 1]);
const result = prevNumber * nextNumber;
parts.splice(i - 1, 3, result);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fells like very specific logic, will it break if i add more parts? or add some complication to the assignment?

Comment thread script.js
parts.forEach((part, i) => {
if (part == "+") {
const prevNumber = parseFloat(parts[i - 1]);
const nextNumber = parseFloat(parts[i + 1]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can extract those 2 lines into a function to avoid repeating yourself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants