Skip to content

Or Chen #14

Open
OrChen555 wants to merge 4 commits into
ColmanDevClubORG:mainfrom
OrChen555:feature-branch
Open

Or Chen #14
OrChen555 wants to merge 4 commits into
ColmanDevClubORG:mainfrom
OrChen555:feature-branch

Conversation

@OrChen555

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 some comments

Comment thread script.js
numberButtons.forEach(btn => {
btn.addEventListener("click", () => {
if (operator) {
if (y!==undefined){

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 also just if(y)

Comment thread script.js
btn.addEventListener("click", () => {
if (operator) {
if (y!==undefined){
y = y*10+ +btn.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 10 into constant variable

Comment thread script.js
}
else{
y = +btn.textContent
addNumberToDisplay(btn.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.

You can extract your main if and else code blocks into functions

Comment thread script.js
addNumberToDisplay('+')
})

subtract.addEventListener('click', function () {

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 only call 1 event listener for all of actions?

Comment thread script.js
equal.addEventListener('click', function () {
if (operator == '+') {
result = x + y;
display.textContent = 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.

I would use if else in here to prevent all those checks, also this line is being called no matter what so you dont need to write it in every line

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

DId you mean switch case?

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.

If you have code that looks like this :

if(condition)
if(secondCondition)
........more checks
........even more checks

Js will read every if statement, unless you will have a return.
But with else if it will only read the relevant none fulfilled condition

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