Skip to content

New solution#25

Open
DinaHK2806 wants to merge 3 commits into
ColmanDevClubORG:mainfrom
DinaHK2806:new-solution
Open

New solution#25
DinaHK2806 wants to merge 3 commits into
ColmanDevClubORG:mainfrom
DinaHK2806:new-solution

Conversation

@DinaHK2806

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 i started to review this and notices that this is the same as your last one, please refer to the prev review (you opened 2 prs for the same changes i think)

Comment thread script.js
@@ -0,0 +1,74 @@
let display=document.querySelector('.display')
let x,y;

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 more meaningful names? x and y are not really indicating what those variables are

Comment thread script.js
let multiply = document.getElementById('multiply')
let divide = document.getElementById('divide')

plus.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.

If you can target all of the operators, you will be able to use 1 function for all of them instead of 4 like now

Comment thread script.js
display.textContent='+';
})
subtract.addEventListener('click', function(){
operator='-';

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.

Hardcoded strings should be saved inside constants variables

Comment thread script.js
display.textContent='/';
})

let equal = document.querySelector('#equal')

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 variables on top of the file

Comment thread script.js
let num = document.querySelectorAll('.number').forEach(btn=>{
btn.addEventListener('click', function(){
if(!operator){
x=Number(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.

This could be NAN add a check for it

Comment thread script.js
x=Number(btn.textContent);
display.textContent=btn.textContent;
}
else{

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.

With early return statement above you dont need this else

Comment thread script.js
result=x+y;
display.textContent=result;
}
if(operator=='-'){

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.

Add else if to not check all of the ifs every time

Comment thread script.js

})

let clear = document.getElementById('clear')

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 this variable on top of this file

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