Skip to content

Solution#24

Open
DinaHK2806 wants to merge 2 commits into
ColmanDevClubORG:mainfrom
DinaHK2806:solution
Open

Solution#24
DinaHK2806 wants to merge 2 commits into
ColmanDevClubORG:mainfrom
DinaHK2806: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 left you some comments

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 better names for it then x and y?
Your variable names should indicate what you mean

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 will add some common class to your operators you could have array of elements that you will loop and apply the event listener - its a bit shorter

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

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

Comment thread script.js

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

let num = document.querySelectorAll('.number').forEach(btn=>{

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 is good practice, in my above comment i referred to something like this

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 I would 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.

If you will add a return statement above here, you will not need the else part

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.

Use else it to avoid checking all 4 of those checks every time

Comment thread script.js
}
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.

Maybe use it after all the ifs? and do it in 1 line and not 4 like you have in here

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