These are chat archives for FreeCodeCamp/HelpJavaScript

15th
Nov 2017
harsh makadia
@harsh-makadia
Nov 15 2017 02:12

Is it ok to use objects without double quote?

For Eg- var myObj = { name:"Zed", age:21, car:null };

Claudio Restifo
@Marmiz
Nov 15 2017 02:20

is it ok to use objects without double quote?

If you mean a string value inside an object, yes. You can use double/single quotes or template literals

var o = {
name: 'free',
surname: "code",
attribute: `camp`,
}
abraham anak agung
@padunk
Nov 15 2017 02:28
@Marmiz hey i don't know you could use`` too for the string
Claudio Restifo
@Marmiz
Nov 15 2017 02:40
Technically they are template literals, They are an ES15 standard I believe.
Allows you to do sweet stuff like:
var a = 5;
var b = 7;

console.log(`the sum of ${a} + ${b} is ${a+b}`)
They are at the core of templates in Vue.js or in libraries like styled-components
abraham anak agung
@padunk
Nov 15 2017 02:45
@Marmiz cool, do you know Vue? i wonder what to learn next Vue or Phyton. Any suggestion?
Claudio Restifo
@Marmiz
Nov 15 2017 02:49

well one's a framework in JS, the other is a programming language. :D

My suggestion in general is: focus on one thing, and learn it good.

abraham anak agung
@padunk
Nov 15 2017 02:54
@Marmiz ok, Thank you. I think i will get deep with JS :smile:
CamperBot
@camperbot
Nov 15 2017 02:54
padunk sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1099 | @marmiz |http://www.freecodecamp.org/marmiz
Henry
@GitHub-Henry
Nov 15 2017 03:49
@padunk YDKJS learn it, live it, love it :shipit: :dizzy:
abraham anak agung
@padunk
Nov 15 2017 03:50
@GitHub-Henry I already read the first part, the book is awesome
Henry
@GitHub-Henry
Nov 15 2017 03:51
@padunk 6 in the set, enjoy the read
abraham anak agung
@padunk
Nov 15 2017 03:52
yup. the problem is i don't like ebook. Paper book is more convenient for me :smile:
Conor Murphy
@cmurphy580
Nov 15 2017 04:46
@khaduch I was looking for something like this https://github.com/ariya/kinetic
does anyone know how i can fix this scroll so it does not cut off the last card? i believe it has to do with the 'display: inline flex' on the container, but when i change it to inline the cards alignment is all messed up. https://codepen.io/cmurphy580/pen/WXEZrw?editors=1100
Ken Haduch
@khaduch
Nov 15 2017 05:11

@cmurphy580 - I don't know why you tagged me, I wonder if you meant to tag someone else? Unless this is related to something that happened so long ago that I cannot remember? :)

But it's a neat site - although it doesn't seem to "snap" to particular points? And I cannot see what you mean about cutting off the last card - it looks fine on my laptop?

Conor Murphy
@cmurphy580
Nov 15 2017 05:16
@khaduch It was a message from a long time ago. Thanks for the feedback.
CamperBot
@camperbot
Nov 15 2017 05:16
cmurphy580 sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3502 | @khaduch |http://www.freecodecamp.org/khaduch
Aizaz Shahid
@aizazshahid
Nov 15 2017 08:44
about @camperbot
CamperBot
@camperbot
Nov 15 2017 08:44
:star2: 3403 | @camperbot |http://www.freecodecamp.org/camperbot
Tiago Correia
@tiagocorreiaalmeida
Nov 15 2017 09:53
hello everyone
Marius Nicolae
@bytao7mao
Nov 15 2017 11:05
hello guys, i need some help, in some condition
Markus Kiili
@Masd925
Nov 15 2017 11:08
@bytao7mao Just post the question you have.
Marius Nicolae
@bytao7mao
Nov 15 2017 11:09
i need help on manipulating the JSON, i need to return country with only that name that the user input
if i comment my last function and i de-comment my last data.apped it will return me Full list with battle + all countries
alpox
@alpox
Nov 15 2017 11:12
@tiagocorreiaalmeida Good morning :D
Marius Nicolae
@bytao7mao
Nov 15 2017 11:12
For better understanding look now my return
it is a list with all Battles, and it shows winner or loser or equal from each country
but i want that when user search for a country to filter result with only that country
country are linked with winner/loser by ID
they share same ID
Stephen James
@sjames1958gm
Nov 15 2017 11:14
@bytao7mao If you look in the console you will see an error that myFunction is not defined.
With codepen it is often that javascript cannot be referenced by HTML.
Use javascript to assign handler to input element
Marius Nicolae
@bytao7mao
Nov 15 2017 11:15
^ how
my console shows nothing
Stephen James
@sjames1958gm
Nov 15 2017 11:18
@bytao7mao Also, myFunction is defined inside of compare which makes it even more inaccessible
document.querySelector("#ss").addEventListener("keyup", myFunction);
Edit ^^
@bytao7mao You also have further scoping issues - your countries variables is only defined in the getJSON callback
Which makes it inaccessible to myFunction.
Marius Nicolae
@bytao7mao
Nov 15 2017 11:25
$.getJSON(API_URL, function(data){
    const countries = data.countries;
    const battles = data.battles;   
    compare(battles, countries);
  })
these ?
Stephen James
@sjames1958gm
Nov 15 2017 11:29
Yes. countries is only going to be defined inside of that function(data) {}
you will need to make the variable more global to be accessible by your input handling function
Marius Nicolae
@bytao7mao
Nov 15 2017 11:31
allright
Stephen James
@sjames1958gm
Nov 15 2017 11:31
$(function(){
  let countries, battles;
  $.getJSON(API_URL, function(data){
    countries = data.countries;
   battles = data.battles;   
  })
document.querySelector("#ss").addEventListener("keyup", myFunction);
function myFunction(e) {
}
})
Then you would need to loop over the countries comparing the input to the name property of each country
Marius Nicolae
@bytao7mao
Nov 15 2017 11:33
shouldn't be set document.querySelector("#ss").addEventListener("keyup", myFunction); function myFunction(e) { into a var ?
Stephen James
@sjames1958gm
Nov 15 2017 11:34
@sjames1958gm You could but you don't have to
const input = document.querySelector("#ss")
input.addEventListener("keyup", myFunction);
Marius Nicolae
@bytao7mao
Nov 15 2017 11:38
well, i did as you said
now, i think my statement is not allright , because it doesn't return nothing :|
is the winner var's fault ? it is instantiated inside forEach loop
Stephen James
@sjames1958gm
Nov 15 2017 11:42
@bytao7mao You are still defining all that inside the compare function loop - so that code assigns 448 event handlers .
I would move that out of the compare function (remove the onkeyup from the HTML) and put a console.log in the myFunction to see if it get's there.
If you console.log the input value then you can meet the first goal of just getting the myFunction to run when you enter data.
Marius Nicolae
@bytao7mao
Nov 15 2017 11:44
allright
Marius Nicolae
@bytao7mao
Nov 15 2017 12:37
it gives me battles not defined
but it is defined...
Markus Kiili
@Masd925
Nov 15 2017 12:40
@bytao7mao You declare it inside the getJSON callback function. JS has function scope, so it can only be used inside that function. Therefore using it is on the global scope gives an error.
Marius Nicolae
@bytao7mao
Nov 15 2017 12:41
so, what should i do
declare outside the scope?
Markus Kiili
@Masd925
Nov 15 2017 12:46
@bytao7mao That structure is fine where you call another function and pass the data as an argument compare(battles, countries);.
Marius Nicolae
@bytao7mao
Nov 15 2017 12:47
allright
Then, what is wrong ? the if statement ?
pocahontas123
@pocahontas123
Nov 15 2017 13:11
Hello, i have a simple question about regex in javascript. Can somebody help me real quick :)
How do in find "-" with regex ?
Blauelf
@Blauelf
Nov 15 2017 13:23
What do you mean? /-/ should match.
pocahontas123
@pocahontas123
Nov 15 2017 13:23
Hello, i think i found what i was looking for
\/^|[ _A-Z]+/gi;
i wanted to split() at every "space" "_" "-" and uppercase
let regex = /^|[ _A-Z]+/g;
Well, still doesn' work as intended :X
Blauelf
@Blauelf
Nov 15 2017 13:29
Within a character set, - defines ranges, and if you want to take it literally, you'll need to escape it using \, like /[\s_\-]+|(?!^)[\s_\-]*(?=[A-Z])/g
pocahontas123
@pocahontas123
Nov 15 2017 13:30
Pfff to complicated for me :/
(?!^) is for lookahead google said
So it mean when i find a uppercase
it look just before it
?
Blauelf
@Blauelf
Nov 15 2017 13:31
Negative lookahead. So not at start of line.
(?=[A-Z]) means followed by an uppercase letter.
pocahontas123
@pocahontas123
Nov 15 2017 13:32
ok
Blauelf
@Blauelf
Nov 15 2017 13:32
This uses - in the range sense, while [\s\-_] uses it literally.
pocahontas123
@pocahontas123
Nov 15 2017 13:34
thanks
Blauelf
@Blauelf
Nov 15 2017 13:34
There are simpler regular expressions, it was just an example how one could use the dash/hyphen/whatever its name is - within character sets.
pocahontas123
@pocahontas123
Nov 15 2017 13:34
Will try to figure it out
thanks Blauelf
@Blauelf thanks
CamperBot
@camperbot
Nov 15 2017 13:36
pocahontas123 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4650 | @blauelf |http://www.freecodecamp.org/blauelf
Marius Nicolae
@bytao7mao
Nov 15 2017 15:40
hello guys, can someone help me in a JSON-API project to finish a filter statement ?
Jason Luboff
@JLuboff
Nov 15 2017 16:17
@cmccormack You around?
Kristina
@kikidesignnet
Nov 15 2017 17:42
Hello? Can you check this Stackoverflow question that I posted out, please? https://stackoverflow.com/questions/47313880/how-to-prevent-zero-from-appearing-in-calculator
Kaz Baig
@kbaig
Nov 15 2017 17:55
@kikidesignnet Easiest way to manage this is probably storing the previous keypress so that you know how to act when a new key is pressed. This way, if two operators are pressed in a row, you can control it. If an operator is pressed after a number, you can control that
Kristina
@kikidesignnet
Nov 15 2017 17:57
Yes, that's what I did but every time I press another operator after the first operator, it kept adding "0", making for example, "5+0-", when I only pressed "5", "+", "-"
So I'm tying to fix the Zero problem first
Kaz Baig
@kbaig
Nov 15 2017 18:03
@kikidesignnet here:
 subMatharray.push(mainMath);
    prevKey = "numbertest";

    if(prevKey == "numbertest") {
      subMatharray.push(keyitem);
      // some other stuff
    }
hmm idk why the formatting is off
anyways
you're pushing mainMath into your array
and mainMath defaults to 0
so you need to not do that if the previous keypress was an operator
Kristina
@kikidesignnet
Nov 15 2017 18:12
Please check out the slackOverFlow question that I posted, someone posted a good solution that I'm going to try out... If all goes well, I might be able to solve the repeating operator problem...
Markus Kiili
@Masd925
Nov 15 2017 18:15
@JLuboff I started doing the portfolio page (no, I am not lying).
Jason Luboff
@JLuboff
Nov 15 2017 18:17
@Masd925 Wow! I'm impressed :D
@Masd925 Finished my pinterest clone. It's basic, but checks all the user stories. https://jlpinterest.glitch.me/ it is acting a little goofy on glitch (where as locally it wasn't)
Markus Kiili
@Masd925
Nov 15 2017 18:18
@JLuboff ok, nice.
Markus Kiili
@Masd925
Nov 15 2017 18:26
@JLuboff Bloody job interview coming soon => stressed.
Jason Luboff
@JLuboff
Nov 15 2017 18:26
@Masd925 Eh. Just go in and be confident! You know what you're talking about/doing
Markus Kiili
@Masd925
Nov 15 2017 18:27
@JLuboff I have been in like 2-3 inteviews in last 20 years and in only one IT related.
Jason Luboff
@JLuboff
Nov 15 2017 18:28
Dang. You really like to stick in one place eh?
Markus Kiili
@Masd925
Nov 15 2017 18:29
@JLuboff Yeah, and have done some business-like things too so not being on the job market always.
Jason Luboff
@JLuboff
Nov 15 2017 18:30
Ya.. well to be fair my last interview was... almost 4 years ago now. I've been here since!
Tiago Correia
@tiagocorreiaalmeida
Nov 15 2017 18:53
@JLuboff hey, yesterday we talked about this but somehow I got a bit confused, if I have a collectun that has an array of user id's will I be able to link them to the user later whe needed to show data?
Jason Luboff
@JLuboff
Nov 15 2017 18:56
@tiagocorreiaalmeida You can use an aggregate with $lookupto do so but can get a bit complicated
@tiagocorreiaalmeida Check out my pinterest clone when you get a chance https://jlpinterest.glitch.me
Tiago Correia
@tiagocorreiaalmeida
Nov 15 2017 18:58
was allready chcecking ehehhe
Jason Luboff
@JLuboff
Nov 15 2017 18:59
:+1:
Tiago Correia
@tiagocorreiaalmeida
Nov 15 2017 19:01
looks good just to be sure
image.png
can youcheck on this one how many lines from me are there?
beside that looks good and congrats mate backend is over for you time for some react :D
anyway my situation is this one
image.png
then later I will have to link the user name to it on the page that show's all the books
Jason Luboff
@JLuboff
Nov 15 2017 19:02
@tiagocorreiaalmeida What size screen are you on? I developed on 1920x1080 so...didn't pay attention to how it might affect things on smaller screen resolutions lol
Tiago Correia
@tiagocorreiaalmeida
Nov 15 2017 19:03
that's a print of the image mate just asked to see on the db how many likes from my user you got on that post cause it seems it bugged for a while :D
Jason Luboff
@JLuboff
Nov 15 2017 19:04
@tiagocorreiaalmeida Oooohh I didn't notice that. Wtf. I bet I put only myself as the restricter for that lol. I'll double check it. Thanks
CamperBot
@camperbot
Nov 15 2017 19:04
jluboff sends brownie points to @tiagocorreiaalmeida :sparkles: :thumbsup: :sparkles:
:cookie: 442 | @tiagocorreiaalmeida |http://www.freecodecamp.org/tiagocorreiaalmeida
Jason Luboff
@JLuboff
Nov 15 2017 19:04
And heres how I structured my document
Ronique Ricketts
@RoniqueRicketts
Nov 15 2017 19:04
hahaha
Jason Luboff
@JLuboff
Nov 15 2017 19:04
blob
Tiago Correia
@tiagocorreiaalmeida
Nov 15 2017 19:05
that's a great idea
for each game store an object with the user info in this case the id and name
Jason Luboff
@JLuboff
Nov 15 2017 19:05
Yup
Tiago Correia
@tiagocorreiaalmeida
Nov 15 2017 19:06
my idea to handle the trade part is you make a request then the book is added to your trades pending you go there and set what book you wanna offer to the other user and only them the user see's the request
not sure if it's a great idea but still's less confusing than the example one
Jason Luboff
@JLuboff
Nov 15 2017 19:06
Thats along the lines of what I did
And my query should be fine for the counter for likes.. wtf.. hmm
Tiago Correia
@tiagocorreiaalmeida
Nov 15 2017 19:07
I think in your case you later the user selects from the other user a game in my case I select a book for trade and still im the one who decides what book I wanna give in trade for the other
does it has duplicates of my user?
btw looks lit smaller than the trade booking app
little
the project
Jason Luboff
@JLuboff
Nov 15 2017 19:25
I'm lost at what you said lol
@tiagocorreiaalmeida I don't get how you were able to get multiple likes... It only shows you in my array once lol
Marius Nicolae
@bytao7mao
Nov 15 2017 19:35
guys, i'am almost there with the project, can someone give me a tip about how to implement the filter to show winner and loser country ?
now when user search a country it returns only defender/loser, and only country
Conor Murphy
@cmurphy580
Nov 15 2017 19:37
@bytao7mao store the data in an object with the winner being one of the properties on the object
Marius Nicolae
@bytao7mao
Nov 15 2017 19:37
allright
and then ?
Tiago Correia
@tiagocorreiaalmeida
Nov 15 2017 19:38
I pressed the like button like crazy but if it did the backend job well then that's great congrats @JLuboff :D
Conor Murphy
@cmurphy580
Nov 15 2017 19:39
@bytao7mao I don't think i get your question sorry
Marius Nicolae
@bytao7mao
Nov 15 2017 19:39
right now if you look at code
it shows all countries , and state which is winner and loser
i want when user search by Italy to show Only Italy
and if is winner or loser
Jason Luboff
@JLuboff
Nov 15 2017 19:41
@tiagocorreiaalmeida Ah...ya if I smash it it does it. But who is smashing the like button like that?!
Tiago Correia
@tiagocorreiaalmeida
Nov 15 2017 19:41
just me :D
Jason Luboff
@JLuboff
Nov 15 2017 19:41
I'm guessing its due to the database connection taking too long
Tiago Correia
@tiagocorreiaalmeida
Nov 15 2017 19:42
yeah I was just trying to understand if it caused backend issues nothing more congrats!!
Jason Luboff
@JLuboff
Nov 15 2017 19:42
@tiagocorreiaalmeida Thanks
CamperBot
@camperbot
Nov 15 2017 19:42
jluboff sends brownie points to @tiagocorreiaalmeida :sparkles: :thumbsup: :sparkles:
api offline
Marius Nicolae
@bytao7mao
Nov 15 2017 19:44
i've changed some code and now it shows me only the result : tie, win, lose
Tiago Correia
@tiagocorreiaalmeida
Nov 15 2017 19:46
anyone around who has used lodash?
Jason Luboff
@JLuboff
Nov 15 2017 19:49
I think I've only used it when going through Andrew's udemy course
Conor Murphy
@cmurphy580
Nov 15 2017 19:49
Can anyone tell me why when I change the value on 'projects-wrap' from inline to inline-flex, the last card loses its margin on the right side?
https://codepen.io/cmurphy580/pen/WXEZrw?editors=1100
AbrisM
@AbrisM
Nov 15 2017 20:26
I see slides and comments but I don't see anything in the slides
Marius Nicolae
@bytao7mao
Nov 15 2017 20:29
guys, can someone correct my code ? ... i'm really struggling for 2 days long, if i input a country which i already know that is a winner, it returns me the result of that country only once (with if statement), or infinite (with while loop), i just want to return by input-search only the country that i searched for but with all results(winner,loser,TIE)...
Tiago Correia
@tiagocorreiaalmeida
Nov 15 2017 21:41
@JLuboff have a minute or two?
Jason Luboff
@JLuboff
Nov 15 2017 21:41
..maybe
Tiago Correia
@tiagocorreiaalmeida
Nov 15 2017 21:42
im trying to pull the object out
wait
I saw the mistake...
:D
Jason Luboff
@JLuboff
Nov 15 2017 21:42
As someone said to me yesterday...sometimes just writing it out helps ;)
Tiago Correia
@tiagocorreiaalmeida
Nov 15 2017 21:43
as alpox says just duck duck
duck rubber*
Jason Luboff
@JLuboff
Nov 15 2017 21:43
duck rubber? or rubber duck>?
Tiago Correia
@tiagocorreiaalmeida
Nov 15 2017 21:44
rubber duck sorry im new to the term :D
Jason Luboff
@JLuboff
Nov 15 2017 21:45
:D
Kristina
@kikidesignnet
Nov 15 2017 22:01
Can anyone take a look at my code one more time? After I edited the code to prevent operators from being entered if there's no number was entered, I was unable to edit that problem if someone press "5+", but changed his mind and pressed "-", changing it to "5-" in history area. It's in function addOperator(keyitem) and the code I'm working on is if(prevKey == "numbertest") { subMatharray.push(keyitem); prevKey = "operatortest"; mainMath = "0"; console.log("addOpArraymainMathElse: " + mainMath); console.log("addOpArraySubArrayElse: " + subMatharray); console.log("addOpArrayPrevKeyElse: " + prevKey); } else if (prevKey == "operatortest" && mainMath == "0") { oppArray.shift(); opkeyitem = oppArray.toString(); subMatharray.splice(-2, 2); subMatharray.push(opkeyitem); subMatharray.push("test"); /*oppArray = [];*/ console.log("addOpArraySubArray: " + subMatharray); console.log("addOpArrayPrevKey: " + prevKey); console.log("addOpArrayoppArray: " + oppArray); }
Darshan
@Dave1089
Nov 15 2017 22:25
Having hard time to convert an array into a list object
For eg. 
console.log(arrayToList([10, 20]));
output ::->  {value: 10, rest: {value: 20, rest: null}}
Tiago Correia
@tiagocorreiaalmeida
Nov 15 2017 22:54
any idea why when the return book.update runs it does returns null on the then?
Jason Luboff
@JLuboff
Nov 15 2017 22:55
becuase you have it so that if the book is find to return null?
Diego Mayer
@Chrono79
Nov 15 2017 22:55

@Dave1089 something like this?

function Node(value, rest = null) {
  this.value = value;
  this.rest = rest;
}

function arrayToList(arr) {
  var list = null, currentNode = null;
  arr.forEach(function(val){
    if (!list) {  
      list = new Node(val, null);
      currentNode = list;
    } else {
      currentNode.rest = new Node(val, null);
      currentNode = currentNode.rest;
    }
  });
  return list;
}

arrayToList([10, 20]);

Note that this returns Node class objects

Tiago Correia
@tiagocorreiaalmeida
Nov 15 2017 22:56
yeah but Book.findOne({ id: id, "owners.user_id": req.user.id}) if an user doesnt exists on the list it wont return turn so based on that I can push the user to ther
there*
and its returning null when I update the collection and push the user to there cause im watching the db and its updating the collection when I do it
Jason Luboff
@JLuboff
Nov 15 2017 23:00
Dunno
Diego Mayer
@Chrono79
Nov 15 2017 23:00

@Dave1089

function arrayToList(arr) {
  var list = null, currentNode = null;
  arr.forEach(function(val){
    if (!list) {  
      list = {value: val, rest: null};
      currentNode = list;
    } else {
      currentNode.rest = {value: val, rest: null};
      currentNode = currentNode.rest;
    }
  });
  return list;
}

arrayToList([10, 20, 30]);

This seems more similar to what you asked for

Kristina
@kikidesignnet
Nov 15 2017 23:12
how do you put that in code format?
Jason Luboff
@JLuboff
Nov 15 2017 23:12
```
shift+enter for new line ,paste code, shift+enter for new line
```
Diego Mayer
@Chrono79
Nov 15 2017 23:14
adding js (or css, html and such) after the first ``` gives you nice coloring pattern
Jason Luboff
@JLuboff
Nov 15 2017 23:16
@Chrono79 Did you check out my pinterest clone?
@Chrono79 :birthday: :cake:
Diego Mayer
@Chrono79
Nov 15 2017 23:18
@Dave1089 what do you mean with only two levels deep, it'll work with arrays of n elements
Darshan
@Dave1089
Nov 15 2017 23:20
@Chrono79 sorry, never mind, just re ran the code
thanks @Chrono79
CamperBot
@camperbot
Nov 15 2017 23:20
dave1089 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4600 | @chrono79 |http://www.freecodecamp.org/chrono79
Kristina
@kikidesignnet
Nov 15 2017 23:21
Thanks @JLuboff !
CamperBot
@camperbot
Nov 15 2017 23:21
kikidesignnet sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2265 | @jluboff |http://www.freecodecamp.org/jluboff
Kristina
@kikidesignnet
Nov 15 2017 23:24
if(prevKey == "numbertest") {
      subMatharray.push(keyitem);
      prevKey = "operatortest";

      console.log("addOpArraymainMathElse: " + mainMath);
      console.log("addOpArraySubArrayElse: " + subMatharray);
      console.log("addOpArrayPrevKeyElse: " + prevKey);
    } else if (prevKey == "operatortest") {
           subMatharray.push("test");
    }
This is the code that I'm working on that's giving me a lot of problems! It's https://codepen.io/kikibres/pen/vWJxBW
I couldn't get it to do anything if I press second operator after I press the first operator...
Jason Luboff
@JLuboff
Nov 15 2017 23:27
@Chrono79 Thanks for taking a look
CamperBot
@camperbot
Nov 15 2017 23:27
jluboff sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4601 | @chrono79 |http://www.freecodecamp.org/chrono79
Diego Mayer
@Chrono79
Nov 15 2017 23:28
No problem
@kikidesignnet why don't you replace the last operator if you click more than one?
test the last value of that array
Kristina
@kikidesignnet
Nov 15 2017 23:32
I'm trying to but as you can see
if(mainMath === null && prevKey == null) { 
      return;
    }
prevent me from entering the operators more than once
it works if one press the operators at first without entering numbers, but not after one enter the numbers
So I was trying to make this code work only if numbers isn't pressed first
Diego Mayer
@Chrono79
Nov 15 2017 23:35
@kikidesignnet you do this: oppArray.push(keyitem);without any test
do something like this:
if (!['+', '-', '*', '/'].includes(oppArray.slice(-1)[0])) oppArray.push(keyitem);
That's an example, you have more than 4 operators
Kristina
@kikidesignnet
Nov 15 2017 23:39
where?
Diego Mayer
@Chrono79
Nov 15 2017 23:42
@kikidesignnet You have to look at all your code (it's not so short)
in the function addOperator you initialize prevKey as null every time, is that right?
Kristina
@kikidesignnet
Nov 15 2017 23:43
I'm looking in the function addOperator(keyitem){
that's where all the actions are
yes, that's because I wanted the prevKey to be blank for mainMath == null.. As you can see, without the if(mainMath ===null), I can enter more than one operator...
with that in place, if someone press an operator without pressing a number, it doesn't do anything. Therefore, one needs to enter a number so that he can enter an operator
Diego Mayer
@Chrono79
Nov 15 2017 23:47
@kikidesignnet but how do you know what was prevKey before if you always initialize it?
Sorry, maybe there is some logic in that, but I'm not seeing it
Kristina
@kikidesignnet
Nov 15 2017 23:49
That is what I was trying to do, I was trying to make the mainMath ===null work only for the beginning, and if anyone entered number, then this statement isn't needed...and I thought prevKey might be the way to do this...
I tried adding if subMatharray is blank... but it didn't work
like this
if(mainMath === null && subMatharray == []) { 
      return;
    }
Diego Mayer
@Chrono79
Nov 15 2017 23:52
@kikidesignnet you can't compare arrays like that
use subMatharray.length === 0
Kristina
@kikidesignnet
Nov 15 2017 23:53
ugh! I didn't even think of that!!! thanks @Chrono79 !
CamperBot
@camperbot
Nov 15 2017 23:53
kikidesignnet sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4602 | @chrono79 |http://www.freecodecamp.org/chrono79
Kristina
@kikidesignnet
Nov 15 2017 23:54
With that in place, I will now see if I can swap the operators
Diego Mayer
@Chrono79
Nov 15 2017 23:54
Go for it :+1:
Kristina
@kikidesignnet
Nov 15 2017 23:54
so there's no need for prevKey == null
Anyway, I gotta go to the gym. See you later!