These are chat archives for FreeCodeCamp/HelpJavaScript

16th
Nov 2017
Diego Mayer
@Chrono79
Nov 16 2017 00:09
:wave:
Chris
@bestintown23
Nov 16 2017 00:10
help, i am trying to add a section to my page to display my prices for work, problem is if you look at the page, where is says"the cost" is way off to the right of the page but i need it to be on the left. https://codepen.io/bestintown23/pen/bYoqrO
AbrisM
@AbrisM
Nov 16 2017 00:17
Hi all is there a weird bug going around? I can't see anything in chat
Jason Luboff
@JLuboff
Nov 16 2017 00:17
No..chat is fine.. but if you can't see anything you probably wont see this
AbrisM
@AbrisM
Nov 16 2017 00:18
I see your response
but I don't see the rest of chat haha
Yes its stuck on 64 chat comments
Okay now I finally see the rest of the chat after relogging in and refreshing 4 times
AbrisM
@AbrisM
Nov 16 2017 00:24
Its a bug. I clicked on the 64 comments and can''t see anything new now
Anyone alive in-chat?
Chris
@bestintown23
Nov 16 2017 00:24
i am
@AbrisM
AbrisM
@AbrisM
Nov 16 2017 00:24
Okay
Yea the rest of the chat is gone lol
Joshua Arnett
@josha5
Nov 16 2017 00:41
Can anyone help me with highlighting buttons in an array one at a time?
Lets say we have an array with [button1, button2, button3]. How would I highlight each button one at a time
abraham anak agung
@padunk
Nov 16 2017 01:35
@josha5 what you mean by highlight? you could change the color in css with :hover
kha97
@kha97
Nov 16 2017 03:56

hey guys i am on the simon game project and for the sequence of backgroundcolors to show up and come back to their original colors i used settimeout but itts not working

case 'red':
     document.getElementById(colorArr[randArr[i]]).style.backgroundColor='#FF4545';
     setTimeout(function (){
         document.getElementById(colorArr[randArr[i]]).style.backgroundColor=colorArr[randArr[i]];    },100);
     break;

and its the same for the rest of three colors what am i doing wrong ?

Hendrik W.
@sol-idsnake
Nov 16 2017 04:07
i'm by far not qualified to provide an answer, but from what i've seen the getElemenyById code has to have ' ' in the parentheses
also, what is the inspector telling you ?
kha97
@kha97
Nov 16 2017 04:09
@sol-idsnake the colorArr arry is made up of string of the name of colors and I should have mentioned that the first line works as in the background color changes but it does not change back to its original color so i think the problem is with settimeout somehow
Kristina
@kikidesignnet
Nov 16 2017 04:28
Ugh! I still need help!!
if (["/", "*", "+", "-"].indexOf(prevKey) > -1) {
      oppArray.shift();
      opkeyitem = oppArray.toString();
      subMatharray.splice(-2, 2);
      subMatharray.push(opkeyitem);
      oppArray = [];
      prevKey = null;
      console.log("addOpArraySubArray: " + subMatharray);
      console.log("addOpArrayPrevKey: " + prevKey);
      console.log("addOpArrayoppArray: " + oppArray);
    } else /*if(prevKey == "numbertest") */{
      subMatharray.push(keyitem);
      prevKey = keyitem;
      console.log("addOpArraySubArrayElse: " + subMatharray);
      console.log("addOpArrayPrevKeyElse: " + prevKey);
      console.log("addOpArrayoppArray: " + oppArray);
    }
This is from my Calculator Codepen: https://codepen.io/kikibres/pen/vWJxBW
Claudio Restifo
@Marmiz
Nov 16 2017 04:30
@kha97 It's hard to say only but that snippet, but be aware that setTimeout returns a number id corresponding to the function itself...so if you are relying on its return value it may not be what you expect
kha97
@kha97
Nov 16 2017 04:31
@Marmiz I figured it out guys spelling mistake settimeout with uppercase o
Claudio Restifo
@Marmiz
Nov 16 2017 04:31
@kha97 :+1:
also you are probably way easier off by just using a CSS animation :)
and instead of changing the style, you probably make it easier with changing/swooping class... less specificity :)
Kristina
@kikidesignnet
Nov 16 2017 04:33
So far, I did fix that problem if I press "5" then "+", but changed my mind and press"-", changing "5+" to "5-", however, it doesn't work for other things. For example, "1+2+3" doesn't display properly. Also if I do the same thing I mentioned previously, but add another number like this "5+", then "5-" and add "3+2", it doesn't work properly as well too
kha97
@kha97
Nov 16 2017 04:35
@Marmiz can you elaborate more please :smile: :+1:
Claudio Restifo
@Marmiz
Nov 16 2017 04:53

@kha97 the individual style for an element takes precedence (has higher priority) over the rest in CSS, so on the long run you may have styles overriding some other; that on one hand may be what you want... but makes it less intuitive to maintain.

you can achieve the same effect by adding/removing classes instead of adding style.

//css
.red {
 background: red;
} 

//js
document.getElementById().className = "red"

this way you also split style and CSS from JS :)

abraham anak agung
@padunk
Nov 16 2017 04:56
@kikidesignnet i just look your code, but doesn't look througgh. but avoid using splice as it will change your original array
Kristina
@kikidesignnet
Nov 16 2017 05:11
@padunk I changed it from splice to pop. However, it was supposed to work only if prevKey is an operator :(
Kristina
@kikidesignnet
Nov 16 2017 05:33
Umm... I think I know why. If I press "1+" and then press a number, it still will pop off the last element in the array because the prevKey was an operator...
Therefore, I changed the if statement
if (["/", "*", "+", "-"].indexOf(keyitem) > -1 && ["/", "*", "+", "-"].indexOf(prevKey) > -1)
However, it's not working...
Jay Vora
@jayvora92
Nov 16 2017 05:38
is there a way to get scarpe value
<a class="ytp-title-link yt-uix-sessionlink" target="_blank" data-sessionlink="feature=player-title" href="https://www.youtube.com/watch?v=vsiezuNtpQg">When It Fits, It Works Better</a>
i want to scrape "When It Fits, It Works Better"
Kristina
@kikidesignnet
Nov 16 2017 06:06
Seems like nobody is up at this hour....
Markus Kiili
@Masd925
Nov 16 2017 06:17
@jayvora92 You wan't to get the text inside the anchor element?
Markus Kiili
@Masd925
Nov 16 2017 06:27
Use some method to access the element and then use textContent property likedocument.getElementById("myLink").textContent
Same with jQuery $("#link").text()
GlassMole
@GlassFen
Nov 16 2017 06:44
hi
Abdul-Samii Ajala Olalekan
@jalasem
Nov 16 2017 09:26
hi everyone, I need how do I define a prop in Vue to expect any data type, be it string or object
something like Any in typescript
export default {
    props: {
        complaint: Any
    }
}
Christopher
@bradley1492
Nov 16 2017 09:39
Hello guys,
I work on the sum all primes challenge. https://www.freecodecamp.org/challenges/sum-all-primes
I managed to write an algorithm based on the sieve of erathostenes which gives me all the prime numbers to a certain number. But somehow I have a problem with every multiple of 5 not being deleted. Maybe someone could help.. :)
Heres my pen
https://codepen.io/bradley1492/pen/qVXemm
Blauelf
@Blauelf
Nov 16 2017 09:47
@bradley1492 Never combine filter and splice.
@bradley1492 Instead, you could use something like
function decimizer(value) {
  for(let i = 2; i <= Math.sqrt(value); i++) {
    if(value % i == 0) {
      return false;
    }// end if
  }// end for
  return true;
}// end function decimizer
place = place.filter(decimizer);
Christopher
@bradley1492
Nov 16 2017 09:55
@Blauelf oh ok thanks, the sqrt seems clever and quite flexible. The function seems very logical and like a neat way to do this. Is the reason for never combining filter and splice complicated or easy to explain?
CamperBot
@camperbot
Nov 16 2017 09:55
bradley1492 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4651 | @blauelf |http://www.freecodecamp.org/blauelf
Christopher
@bradley1492
Nov 16 2017 10:00
@Blauelf Thanks a lot it works :)
CamperBot
@camperbot
Nov 16 2017 10:00
bradley1492 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
api offline
Blauelf
@Blauelf
Nov 16 2017 10:10
@bradley1492 It's not at all clever. Cleverer would be for (let i = 2, max = Math.sqrt(value); i < max; i++), as this avoids re-evaluating the square root.
Even better if you tested for %2 and %3 first, and then tested only 6*k+1 and 6*k+5 as divisor candidates.
Still better systems use the remainder of division by 60 :D
Christopher
@bradley1492
Nov 16 2017 10:24
@Blauelf hahhaha okayy. Clever in comparison to my initial approach :)
Christopher
@bradley1492
Nov 16 2017 10:37
@Blauelf hmm okay i thought it works, but only the first two tests work. With the last test I am getting a wrong number which is 72179. Isn`t the for-loop working for every size, and different approaches here are just more efficient?
Here is my code:

function sumPrimes(num) {
// this is the example number
let place = [];
// this is the placeholder array
for (let i = 0; i < num; i++) {
    place.push(i);
}
place.splice(place.indexOf(0), 1);
place.splice(place.indexOf(1), 1);
// deletes 1 and 2
// pushes all the numbers to the place array
function decimizer(value){
    for(let i = 2; i <= Math.sqrt(value); i++) {
    if(value % i == 0) {
      return false;
    }// end if  
}// end for
return true;
}// end function decimizer
place = place.filter(decimizer);
return result = place.reduce((a, b) => a + b, 0);//end reduce  
}// end function
sumPrimes(10);
Blauelf
@Blauelf
Nov 16 2017 10:40
@bradley1492 Maybe for (let i = 0; i <= num; i++) in that first loop?
Christopher
@bradley1492
Nov 16 2017 10:41
@Blauelf Exactly thanks I have to really be careful in these spots...
CamperBot
@camperbot
Nov 16 2017 10:41
bradley1492 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
api offline
Blauelf
@Blauelf
Nov 16 2017 10:41
@bradley1492 I assume those are the cases in which num itself is prime.
Christopher
@bradley1492
Nov 16 2017 10:44
@Blauelf Okay yes this would make sense for me
Blauelf
@Blauelf
Nov 16 2017 10:45
BTW, for (let i = 2; i <= num; i++) and there's no need to cut off 0 and 1 using splice.
Christopher
@bradley1492
Nov 16 2017 10:49
@Blauelf goooodness yeah hahahaha, thats right. I thought about it being quite awkward to do. Thanks :9
CamperBot
@camperbot
Nov 16 2017 10:49
bradley1492 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
api offline
Spyrantis Theodoros
@thodorisanta
Nov 16 2017 13:46

why in line 79 in JS the function call is not working? ( its supposed to change the number of turns in the UI)

https://codepen.io/oshikurou/pen/vWGoee?editors=1111

Pethaf
@Pethaf
Nov 16 2017 13:47
Hey, any JS gurus here?
Blauelf
@Blauelf
Nov 16 2017 13:58
@thodorisanta Please never use the same name for a function and a variable. Functions are like variables declared with var.
Spyrantis Theodoros
@thodorisanta
Nov 16 2017 14:01
@Blauelf OMG . I took some time off of the project and i didnt notice that thank you
CamperBot
@camperbot
Nov 16 2017 14:01
thodorisanta sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4652 | @blauelf |http://www.freecodecamp.org/blauelf
wza62692371
@wza62692371
Nov 16 2017 14:01
Add your JavaScript Slot Machine Slots
Tiago Correia
@tiagocorreiaalmeida
Nov 16 2017 14:09
you have knowledge on something and others might have in other you might have an issue that's simple for another person and hard for you, or the oposite
so why do you need a guru ? @Pethaf :D
Adel
@AdelMahjoub
Nov 16 2017 14:23
@Pethaf while searching for a javascript guru I found this article it iseems he is the guru you are seeking :smile:
Blauelf
@Blauelf
Nov 16 2017 14:25
This guy reminds me of "JavaScript: The good parts". No ++ until you get to the bad parts :D
Adel
@AdelMahjoub
Nov 16 2017 14:26
yes he has a lot of funny statements
Spyrantis Theodoros
@thodorisanta
Nov 16 2017 15:29
how can i change the text color in console? (opera)
Blauelf
@Blauelf
Nov 16 2017 15:34

@thodorisanta In devtools/JavaScript console? It's usually not meant to be changed. This page from last year lists what back then the different console outputs would look like: https://coderwall.com/p/m2trga/enhance-your-js-console-logging-messages

Maybe there's some CSS applied that one could change, but that CSS wouldn't be part of the page, but part of the browser.

Spyrantis Theodoros
@thodorisanta
Nov 16 2017 15:37
@Blauelf it says that you can change it in chrome
Blauelf
@Blauelf
Nov 16 2017 15:39
Just tried on Chrome with console.log("%cTest string", "text-decoration:underline;");, and it indeed works.
Also works on Firefox :D
Don't have some Opera to test.
Internet Exploder won't interpret it.
Spyrantis Theodoros
@thodorisanta
Nov 16 2017 15:43
@Blauelf i tried it on opera and it doesnt works. it treats it like text
Blauelf
@Blauelf
Nov 16 2017 15:49
What do you want to style, and why?
Maybe if we cannot get console.log to change colour, there's another method to output to your console?
Stephen James
@sjames1958gm
Nov 16 2017 16:41
@Blauelf Sweet!
Blauelf
@Blauelf
Nov 16 2017 16:53
@thodorisanta In the comments, someone linked to https://github.com/adamschwartz/log
Jasper
@Jasperaine
Nov 16 2017 17:15
Please could somebody help me, I've almost finished my TICTACTOE project however sometimes the computer randomly does not take its turn?! any help would be greatly appreciated. i think its something to do with the computers turn function but im not sure what! https://codepen.io/Jasperaine/pen/wPrLjq
Ronique Ricketts
@RoniqueRicketts
Nov 16 2017 17:16
anyone else finds the express challenges simpler than the nodejs challenges?
Jason Luboff
@JLuboff
Nov 16 2017 18:01
@RoniqueRicketts Yes, express makes everything easier ;)
Ronique Ricketts
@RoniqueRicketts
Nov 16 2017 18:02
@JLuboff excitement man
I am doing well with the challenges so far.
Jason Luboff
@JLuboff
Nov 16 2017 18:02
:+1:
I've developed all my backend projects with express
Ronique Ricketts
@RoniqueRicketts
Nov 16 2017 18:03
I have 3 challenges left them It should be the challenges. I Hope I do well with the backend challenges.
Jason Luboff
@JLuboff
Nov 16 2017 18:03
I'm sure you'll do fine
Stephen James
@sjames1958gm
Nov 16 2017 18:37
@Jasperaine Could it be if the computers choice is already taken you don't retry?
Ronique Ricketts
@RoniqueRicketts
Nov 16 2017 18:38
@JLuboff thanks for the vote of confidence
CamperBot
@camperbot
Nov 16 2017 18:38
roniquericketts sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2267 | @jluboff |http://www.freecodecamp.org/jluboff
Stephen James
@sjames1958gm
Nov 16 2017 18:38
@Jasperaine Your variable names leave much to be desired w, y, x etc. hard to know what their purpose is
@Jasperaine Well I found your retries, but I guess you only retry 9 times? But there is no guarantee that it would have checked all with 9 tries when you are doing random
Jay Vora
@jayvora92
Nov 16 2017 18:44
@Masd925 Thank you for the reply. Is there any other way i can pull that text. if I add <title> before that, would it make easy?
CamperBot
@camperbot
Nov 16 2017 18:44
jayvora92 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4575 | @masd925 |http://www.freecodecamp.org/masd925
sabahatullah
@sabahatullah
Nov 16 2017 18:53
can someone please help me with this. https://we.tl/44CYVbqEmL
The click event is not working properly
it triggers click when I click way below the actual element
The link above is a wetransfer link that shows a video of that issue
Chris
@bestintown23
Nov 16 2017 19:11
why is 2 out of 3 of my divs showing in a row? nothing seems to work for me... i need them all in a row https://codepen.io/bestintown23/pen/bYoqrO
Kristina
@kikidesignnet
Nov 16 2017 19:22
Help? Still having problems with the problem I've been working on the past few days. Please check out the SlackOverFlow question: https://stackoverflow.com/questions/47337484/js-calculator-variable-prevkey-doesnt-register-values-properly
@bestintown23 I checked your code. They are in row. Btw, have you consider FlexBox?
@bestintown23 Please check out this article. It's helpful: https://scotch.io/tutorials/a-visual-guide-to-css3-flexbox-properties
sabahatullah
@sabahatullah
Nov 16 2017 19:37
can someone please help me with this. https://we.tl/44CYVbqEmL
The click event is not working properly
@sjames1958gm could you help please
it triggers click when I click way below the actual element
Tiago Correia
@tiagocorreiaalmeida
Nov 16 2017 19:41
hello everyone :wave:
Jason Luboff
@JLuboff
Nov 16 2017 19:41
:wave:
Tiago Correia
@tiagocorreiaalmeida
Nov 16 2017 19:41
how's everything?
Jason Luboff
@JLuboff
Nov 16 2017 19:41
Alright..yourself?
Tiago Correia
@tiagocorreiaalmeida
Nov 16 2017 19:42
all good
neeed your opinion if you dont mind @JLuboff I was looking at lookup and it seems to do the job or makes me thing it does but Im not sure if it's the best way of doing it, if you dont mind giving it a look
image.png
for each book owner I need to render the book again
Tiago Correia
@tiagocorreiaalmeida
Nov 16 2017 19:47
but somehow I feel that's like a bad idea
imagina a list with 10times the same book
so im not sure if I should limit a book for user?
or just show the book one time and only the first owner when displaying the entire books list
but then there's another thing imagine one user doens't want to trade it but other would like to do it?:D confused how to do this
Jason Luboff
@JLuboff
Nov 16 2017 19:49
I just had one game, but multiple owners so that I didn't have multiples of the same. And then...I think I went the lazy route of just getting the first one that met the criteria lol. It might be better to provide the trade to all users, but that can get a little dicey too
Tiago Correia
@tiagocorreiaalmeida
Nov 16 2017 19:57
that's what I did 1 book multiple uses im just thinking when showing the list of books how im gonna do it when multiple users own the smae book, cause showing it multiple times looks a bad idea aswell if you have any idea of how I should do it or something im a bit stuck in here :D
Jason Luboff
@JLuboff
Nov 16 2017 19:58
Query the database for the books, not the owners inside the book
Tiago Correia
@tiagocorreiaalmeida
Nov 16 2017 19:58
and when a request is made to the book howshould I handle it?
Jason Luboff
@JLuboff
Nov 16 2017 19:59
Thats up to you ;)
Tiago Correia
@tiagocorreiaalmeida
Nov 16 2017 20:00
uh I think I got an idea of how to do it, thanks @JLuboff
CamperBot
@camperbot
Nov 16 2017 20:00
tiagocorreiaalmeida sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2268 | @jluboff |http://www.freecodecamp.org/jluboff
Kristina
@kikidesignnet
Nov 16 2017 20:04
Help? Still having problems with the problem I've been working on the past few days. Please check out the SlackOverFlow question: https://stackoverflow.com/questions/47337484/js-calculator-variable-prevkey-doesnt-register-values-properly
Adel
@AdelMahjoub
Nov 16 2017 20:09
@kikidesignnet there is a nice library for this, math.js, it has a function to write the calculator in 2 lines
Tiago Correia
@tiagocorreiaalmeida
Nov 16 2017 20:09
image.png
this is what I call a book name
jesus
Amanda
@Amandaan
Nov 16 2017 20:32
Anyone knows how to fix this?
屏幕快照 2017-11-16 下午3.32.22.png
Kaz Baig
@kbaig
Nov 16 2017 20:33
@Amandaan err what's the issue
Amanda
@Amandaan
Nov 16 2017 20:33
I want the text read "The 1 Image of the Album", so I coded like this
var num=0;
oLeftspan1.innerHTML='The '+1+num+' Image of the Album';
But it shows like that "The 10 Image...",
Kaz Baig
@kbaig
Nov 16 2017 20:35
ya because it's going left to right
so 'the' + 1 turns 1 into a string
then 'the 1' + 0 turns 0 into a string
Amanda
@Amandaan
Nov 16 2017 20:35
How can I fix that??
Kaz Baig
@kbaig
Nov 16 2017 20:36
quickest way would be 'The ' + (1 + num) +....
Amanda
@Amandaan
Nov 16 2017 20:37
Thank you!!
Kaz Baig
@kbaig
Nov 16 2017 20:37
:D
Joshua Arnett
@josha5
Nov 16 2017 21:19
Can anyone help me with my simon project
Kaz Baig
@kbaig
Nov 16 2017 21:24
ssssup
Joshua Arnett
@josha5
Nov 16 2017 21:26
@kbaig Bit of a loaded question. So basically I've got my simon project selecting a new square after a correct click. What I need is for it to replay the last square/squares clicked and then the new square
Jason Luboff
@JLuboff
Nov 16 2017 21:27
Store previous moves in an array
Kaz Baig
@kbaig
Nov 16 2017 21:27
^
Joshua Arnett
@josha5
Nov 16 2017 21:27
I am
I can't figure out how to incorporate setTimeout to highlight each item in the array one after another
Kaz Baig
@kbaig
Nov 16 2017 21:28
use setInterval
Joshua Arnett
@josha5
Nov 16 2017 21:29
function replayFlash(pressedButArr) {
  pressedButArr.map(function(x) {
    const originalColor = x.css("background");
    var highLight = x.css("background", "#ffcccc");
    setTimeout(function() {
      var highLighted = x.css("background", originalColor);
    }, 1000);
    count += 1;
    $("#displayCount").text(count);  
    clearTimeout(highLighted);  
  });
}
^this is what I have that is not working
Jason Luboff
@JLuboff
Nov 16 2017 21:29
I used two setTimeouts
The first one is in a loop, in which the second one is called with increasing time length (iterator times static time)
Joshua Arnett
@josha5
Nov 16 2017 21:32
@JLuboff @kbaig Thanks guys I'll give it a try
CamperBot
@camperbot
Nov 16 2017 21:32
josha5 sends brownie points to @jluboff and @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 424 | @kbaig |http://www.freecodecamp.org/kbaig
:star2: 2269 | @jluboff |http://www.freecodecamp.org/jluboff
Joshua Arnett
@josha5
Nov 16 2017 21:33
@JLuboff I'm a bit confused on the second setTimeout
do you have an example
Jason Luboff
@JLuboff
Nov 16 2017 21:36
function secondTimeOut(color, time){
setTimeout(function(){
changeColorPropHere }, time)}

function firstTimeout (){
for(let i = 0; i < moveArray; i++){
secondTimeOut(colorToChange, 500);
}, 500 * (i + 1)) }}
Might be missing some brackets but you get the idea
Joshua Arnett
@josha5
Nov 16 2017 21:37
@JLuboff You are the man thanks!
CamperBot
@camperbot
Nov 16 2017 21:37
josha5 sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
api offline