These are chat archives for FreeCodeCamp/HelpJavaScript

1st
Apr 2018
Brian
@BrianCodes33
Apr 01 2018 06:32
function inAscOrder(arr) {
   for (var i=0; i<arr.length; i++) {
     if (arr[i] < arr[i + 1]) {
       return true;
     } 
     return false;
   }
}

inAscOrder([1, 2, 4, 7, 19])
any idea what im doing wrong
Markus Kiili
@Masd925
Apr 01 2018 06:34
@BrianCodes33 Basic loop logic for testing if many conditions hold, is to seek for a failure and return false, and return true after the loop.
Also make sure you loop the right indices.
i+1 might be out of bounds.
Brian
@BrianCodes33
Apr 01 2018 06:46
ty is there a way to do this w/ functional programming
Markus Kiili
@Masd925
Apr 01 2018 06:50
@BrianCodes33 You can use an array iterator like .every(), .some(), or .reduce(), instead of the loop.
Every (or some) would be a wise choice, because it breaks early on failure.
JeremyHaynes310
@JeremyHaynes310
Apr 01 2018 06:51
@BrianCodes33 Is that a FCC challenge?
Brian
@BrianCodes33
Apr 01 2018 06:52
codewars
JeremyHaynes310
@JeremyHaynes310
Apr 01 2018 06:52
@BrianCodes33 Can you send me the link?
nevermind
I found it
thanks
CamperBot
@camperbot
Apr 01 2018 06:53
sorry briancodes33, you can't send brownie points to yourself! :sparkles: :sparkles:
JeremyHaynes310
@JeremyHaynes310
Apr 01 2018 06:55
@BrianCodes33 I believe this is what you want with a for loop
function inAscOrder(arr) {

   for (var i = 0; i<arr.length; i++) {
      if(arr[i] > arr[i+1]){
        return false
      }

   }
    return true
}
Heres with ever()
function inAscOrder(arr) {
  return arr.every((x, i) => arr[i+1] ? arr[i+1] > x : true)
}
This message was deleted
You can also do recursively
Nazar
@IsaakNazar
Apr 01 2018 07:02
var i = 0; i<arr.length-1; i++
JeremyHaynes310
@JeremyHaynes310
Apr 01 2018 07:03
nah u don't need to -1
Nazar
@IsaakNazar
Apr 01 2018 07:04
when arr[i] will be the last element then arr[i+1] ?
JeremyHaynes310
@JeremyHaynes310
Apr 01 2018 07:05
Say what?
Nazar
@IsaakNazar
Apr 01 2018 07:06
that's why arr.length-1
JeremyHaynes310
@JeremyHaynes310
Apr 01 2018 07:08
But u don't need it
not that it matters
lol
@IsaakNazar If you try with -1 or with out it, it works both ways :)
Nazar
@IsaakNazar
Apr 01 2018 07:11
@JeremyHaynes310 ok, awesome :+1:
JeremyHaynes310
@JeremyHaynes310
Apr 01 2018 07:15
with out takes away the undefined though, so is probably best to -1 :laughing:
sorry with
not without
stoopid JS
0 based index
Markus Kiili
@Masd925
Apr 01 2018 07:16
@JeremyHaynes310 Using arr[i+1] as a condition leads to a bug with array elements that are 0, in your every solution.
JeremyHaynes310
@JeremyHaynes310
Apr 01 2018 07:31
" array of positive integers as input"
You are right though
Markus Kiili
@Masd925
Apr 01 2018 07:32
@JeremyHaynes310 ok, but still best not to use such a condition.
JeremyHaynes310
@JeremyHaynes310
Apr 01 2018 07:32
That is why I said you are right though ;)
Markus Kiili
@Masd925
Apr 01 2018 07:33
@JeremyHaynes310 Yes, yes.
Ion Varsescu
@Nei-V
Apr 01 2018 12:35
hello, I have a question, I'm doing the number the US phone number validation algorithm. I've put the formats in an array in an object like this: [{ format: /^[0-9]{10}$/ }]. The problem: if I access the object directly (array[1].format.test(5555555555)) with a simple if, it works, and I get true. On the other hand, using map: let compare = trueValues.map(function (formatRe) {if comparation - the comparation is in the map - it doesn't work...is like in the map, the regex is not executed. Any ideas? thank you
Ayush Bahuguna
@relentless-coder
Apr 01 2018 12:36
Can someone help me with React's context API?
Stephen James
@sjames1958gm
Apr 01 2018 12:37
@Nei-V What does the comparison look like?
formatRe.format.test("555555555") ?
Ion Varsescu
@Nei-V
Apr 01 2018 12:38
if (formatRe.format == originalString) { - where original string is the input
Stephen James
@sjames1958gm
Apr 01 2018 12:39
@Nei-V formatRe.format is a regex == doesn't seem correct
Ion Varsescu
@Nei-V
Apr 01 2018 12:41
you are a genius @sjames1958gm :) I understand now, i should have used if (formatRe.format.test(originalString)) - this way it works
Stephen James
@sjames1958gm
Apr 01 2018 12:41
if you use this directly array[1].format.test(5555555555) then you should use formatRe.format.test(5555555555) in the .map
Not exactly sure what you are expecting from the .map
:+1:
Ion Varsescu
@Nei-V
Apr 01 2018 12:42
thanks @sjames1958gm
CamperBot
@camperbot
Apr 01 2018 12:42
nei-v sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 9155 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Ion Varsescu
@Nei-V
Apr 01 2018 13:44
Another question - might be trivial. When I have an object, I wnat to show it in the browser window, but it only shows [object Object]. only if I access a property it shows it. I would like to see the object like in the console, like the results you get from an api
Ken Haduch
@khaduch
Apr 01 2018 13:45
@Nei-V - you can always try console.log(JSON.stringify(yourObject)); and see if it shows what you want?
it will definitely show you the structure, but as a JSON string. Maybe it will help?
Ion Varsescu
@Nei-V
Apr 01 2018 13:49
@khaduch thanks, using the stringify works in the return statement works, but it gets very ugly if there are many levels inside the object
CamperBot
@camperbot
Apr 01 2018 13:49
nei-v sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3841 | @khaduch |http://www.freecodecamp.org/khaduch
Donnie
@Donnie-D
Apr 01 2018 13:49
I don't want my background image to repeat. what else could I do because no-repeat dont do a thing lol :smile:
https://codepen.io/Donnie-D/pen/YaydRM
or is it probably jumbotron we cant mess with the position of?
Stephen James
@sjames1958gm
Apr 01 2018 13:55
@Donnie-D Your setting of background in javascript overwrites your individual properties in the css section
@Donnie-D Use "background-image" in your js and you will see the difference
Donnie
@Donnie-D
Apr 01 2018 13:57
@sjames1958gm were you born as a legend or is it something you lately became? :smile: :+1:
Stephen James
@sjames1958gm
Apr 01 2018 13:58
@Donnie-D I am taking a CSS course on Udemy and noticed in the devtools that your css stuff was crossed out
Donnie
@Donnie-D
Apr 01 2018 13:59
so just to make things clear JS takes precedence over CSS when laying out
@sjames1958gm
Stephen James
@sjames1958gm
Apr 01 2018 14:01
@Donnie-D When you use the .css function the styles become element styles which have the highest priority.
They become like <p style="background:url()"/>
If you had assigned a class instead then it would use the normal css class precedence
From dev tools showing that your background style is element style
element.style {
    background-image: url(https://media.giphy.com/media/3o7rc6sa2RvKo8K5EI/giphy.gif);
}
Donnie
@Donnie-D
Apr 01 2018 14:04
nicely put! :clap:
Hey but I used .jumbotron in css which is a class
Stephen James
@sjames1958gm
Apr 01 2018 14:07
@Donnie-D background by itself is a combination of styles, so assigning it to an element blocked all the
specific styles from the class
Donnie
@Donnie-D
Apr 01 2018 14:07
but i suppose as you said above, I was using background property which rules the rest out
yessss lol sorry i was a bit slow in typing lol
another thing is, can we stretch or compress an image using css at all? if theres a property for this there?
for example if i have a few images of various aspect ratios, could i put them all in sort of same stretch of a container which might be bigger than some and smaller than others?
Stephen James
@sjames1958gm
Apr 01 2018 14:09
@Donnie-D Try background-size: cover and see if that works for you
Ken Haduch
@khaduch
Apr 01 2018 14:10
@Donnie-D - when I load your page, it does not repeat the background image, and if I comment out your "background-repeat" CSS line, then it does repeat. So it looks like it doesn't repeat....
Stephen James
@sjames1958gm
Apr 01 2018 14:12
@khaduch He has made changes since the original posting.
Donnie
@Donnie-D
Apr 01 2018 14:12
@khaduch that might be because css by default repeats it. thats why i added that line there
Ken Haduch
@khaduch
Apr 01 2018 14:13
@Nei-V - :point_up: April 1, 2018 9:49 AM - yes, it doesn't always look pretty, but it does at least give you more than [Object object]...
@sjames1958gm @Donnie-D :+1:
Donnie
@Donnie-D
Apr 01 2018 14:15
@khaduch @sjames1958gm @khaduch to you fellas out there. @sjames1958gm do you wear a cape when on computer?
lmao
Stephen James
@sjames1958gm
Apr 01 2018 14:16
:)
Donnie
@Donnie-D
Apr 01 2018 14:18
@sjames1958gm also i was asking someone yesterday if there is a way around but i was abandoned lol so... if you look at my JS part again... you'll see that i had to use 2 arrays with same names backgroundArr and backgroundArr2 in order for me to get the RegExp to work in my loop. is there a way around that?
Stephen James
@sjames1958gm
Apr 01 2018 14:21
@Donnie-D Yeah, that looks like the place for an array of objects
[{condition: "Overcast", url: "https://...}]
Donnie
@Donnie-D
Apr 01 2018 14:24
@sjames1958gm hmmm, i think i can see what you suggest here. so get rid of the both arrays and make an object as you said above. Then further down in my loopy condition refer to those object. properties accordingly
Stephen James
@sjames1958gm
Apr 01 2018 14:25
@Donnie-D Replace one array with this array of objects and ditch the other array
Donnie
@Donnie-D
Apr 01 2018 14:27
yep yep and i am not a chelsea fan but you still have my respect
lol
@sjames1958gm is there anywhere we can actually get the bootstrap documentation at all for whats going under the hood to the classes we are using? is that possible?
Markus Kiili
@Masd925
Apr 01 2018 14:32
@Donnie-D You can look at the standard (non-minified) bootstrap css file.
Donnie
@Donnie-D
Apr 01 2018 14:33
@Masd925 i typed bootstrap css file on google and took me to bootstrap homepage
Amit Patel
@AmitP88
Apr 01 2018 14:35
hey guys, I'm trying to get my (+) button to increment faster on click & hold by implementing this solution https://stackoverflow.com/questions/79816/need-javascript-code-for-button-press-and-hold but for some reason it won't work. There aren't any errors in dev console that indicate that something is wrong with the function, and I've read over the solution (and my implementation of it) over a few times, and I still can't figure out what I'm doing wrong. Please help
Markus Kiili
@Masd925
Apr 01 2018 14:39
@Donnie-D Try to find links to bootstrap css without min, like https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css
.../css/bootstrap.min.css would not be readable (is minified).
It might also be possible to beautify such a minified file to a readable form, but usually the readable form is also available.
Moisés Man
@moigithub
Apr 01 2018 14:53
@AmitP88 the html event name is onmouseup and onmousedown https://www.w3schools.com/jsref/event_onmouseup.asp
if u have a reference to ur html eleemnt var add = document.getElementById("add");
u can use console.dir(add) and inspect
Moisés Man
@moigithub
Apr 01 2018 15:01
@AmitP88 holdit_increment(add, increment, 1000, 2);
pass ur original increment function, instead a empty function
so it gets called on "repeat()"
Amit Patel
@AmitP88
Apr 01 2018 15:03
hmmmm, that worked, but now when I hit the reset button, it automatically sets the timer up to 60
Moisés Man
@moigithub
Apr 01 2018 15:08
@AmitP88 if u click on - it goes back to 60
soo seems some interval still "active"
Amit Patel
@AmitP88
Apr 01 2018 15:08
hmmm, i'm starting to think I should just ditch implementing this lol
Nazar
@IsaakNazar
Apr 01 2018 15:12
@AmitP88 hey Amit, does your pomodoro fit properly on cell phone's screens?
Amit Patel
@AmitP88
Apr 01 2018 15:14

@IsaakNazar on most of them yes, but it's really hard to make the svg circles responsive. I checked it out on https://sizzy.co/?url=https%3A%2F%2Famitp88.github.io%2FPomodoro-Timer%2F

and it seems to look good across a lot of devices

Nazar
@IsaakNazar
Apr 01 2018 15:17
@AmitP88 looks nice, would be awesome if the app fit on screens without scrolling
Amit Patel
@AmitP88
Apr 01 2018 15:18
@IsaakNazar yeah, I wanna do that too, but svg circles are difficult to make responsive
@IsaakNazar plus, i've been working on this project for like 4 weeks now lol
Nazar
@IsaakNazar
Apr 01 2018 15:20
@AmitP88 but finally, it's done :+1:
Amit Patel
@AmitP88
Apr 01 2018 15:21
@IsaakNazar weeeell, sort of. I still need to make the break timer and tie it to the interface via the two radio buttons for work and break =/
Nazar
@IsaakNazar
Apr 01 2018 15:22
@AmitP88 so if you need another couple weeks, then welcome :smile:
Amit Patel
@AmitP88
Apr 01 2018 15:22
lol oh god. at this rate it'll take me a few years just to be ready for a junior position lol
I havent even finished all the front end algorithms yet. I decided to take a break from them and just move forward with the projects
Nazar
@IsaakNazar
Apr 01 2018 15:25
@AmitP88 who knows, maybe very soon you'll get your dream job
me too, I have 3 projects left from frontend, but moved to react, now I'm on halfway of my first react project, I hope :smile:
Amit Patel
@AmitP88
Apr 01 2018 15:26
@IsaakNazar i dunno, I still need to learn advanced js, read all of ydkjs series, and start building react projects, as well as be able to solve 200 algorithms on my own
Nazar
@IsaakNazar
Apr 01 2018 15:28
@AmitP88 me too man, me too, YDKJS still on the toDo list
Amit Patel
@AmitP88
Apr 01 2018 15:28
@IsaakNazar I think what I'll do is skip this functionality for now and focus on building the break timer, since that's basically the other 1/2 of the app
Markus Kiili
@Masd925
Apr 01 2018 15:29
@AmitP88 JS is incredibly big and tough language if you include dom manipulation stuff. I have studied it for three years, but still lot to learn. They are also adding content to the language at good pace, so that doesn't help either.
Nazar
@IsaakNazar
Apr 01 2018 15:30
@AmitP88 For me your app is good enough, maybe you should start another project
Amit Patel
@AmitP88
Apr 01 2018 15:30
@Masd925 tell me about it. I still need to implement es6 later on
@IsaakNazar thanks. I think I'll just get the break timer out the way though, since the interface won't make sense without it
CamperBot
@camperbot
Apr 01 2018 15:30
amitp88 sends brownie points to @isaaknazar :sparkles: :thumbsup: :sparkles:
:cookie: 321 | @isaaknazar |http://www.freecodecamp.org/isaaknazar
Amit Patel
@AmitP88
Apr 01 2018 15:31
@IsaakNazar but thanks for that, I really appreciate it :)
Nazar
@IsaakNazar
Apr 01 2018 15:31
wes bos JS30 helped me a lot to understand DOM manipulation, try it @AmitP88
tutorials are pretty short, and very understandable
Amit Patel
@AmitP88
Apr 01 2018 15:35
oh is that the javascript30 challenge?
build 30 js projects in 30 days?
Nazar
@IsaakNazar
Apr 01 2018 15:38
@AmitP88 yep, you can find it on youtube
Amit Patel
@AmitP88
Apr 01 2018 15:39
@IsaakNazar oh yeah, I definitely want to do that too, but I'm thinking to do that after freecodecamp, especially since it primarily uses es6 (which I want to master)
Nazar
@IsaakNazar
Apr 01 2018 15:42
@AmitP88 well, I started learning js30 with zero knowledge of es6 , Wes really good teacher IMHO
But I have a lot to learn , a lot
Amit Patel
@AmitP88
Apr 01 2018 15:43
@IsaakNazar I want to see if I can do the projects myself though, at least for the most part, so that I can get better
Nazar
@IsaakNazar
Apr 01 2018 15:45
@AmitP88 well, you created Pomodoro and other projects by yourself, so what's up?
Moisés Man
@moigithub
Apr 01 2018 15:45
@AmitP88 seems after u disable the button the mouseup event doesnt get fired
and it "down state" keep running
Amit Patel
@AmitP88
Apr 01 2018 15:47
@moigithub the (+) button only gets disabled when the timer is set at 60 (which is the max)
Moisés Man
@moigithub
Apr 01 2018 15:48
yep... if u hold click and stop at 59 (or less) that "reset problem" dont appear
Amit Patel
@AmitP88
Apr 01 2018 15:50
@moigithub ahhh I see. hmmm, I also get a problem with holdit_decrement and when the timer is set to 00:00. when i hit reset, the timer goes back to 00:00
@moigithub I'm going to work on the break timer first (since that's basically the other 1/2 of the app), but after I get that working right, i'll see if I can come back to this as a final polish to the app
Moisés Man
@moigithub
Apr 01 2018 15:51
so one solution could be remove the disable button code...
or call/fire the mouseup event add.mouseup() (or down)
Amit Patel
@AmitP88
Apr 01 2018 15:52
hmmm, I need the disable code though to prevent the user from being able to go outside the limits of setting the timer to 00:00 (min) and 60:00 (max)
Aniculaesei
@Aniculaesei
Apr 01 2018 15:53
How!Can somebody help me to understand the javascript selectors please?
This is not working.Thank you
<!DOCTYPE html>
<html>
    <head>
        <title>Neeeew</title>
    </head>
    <body>
        <a href = "https://www.facebook.com/"id = "first">First</a>
        <a href = "https://translate.google.com/#auto/ro/interrelated%20nodes">Second</a>

    <script>
    document.onload = function(){
        var el = document.getElementById("first");
        el.href = "https://www.linkedin.com";


    }

    </script>
    </body>
</html>
Moisés Man
@moigithub
Apr 01 2018 15:55
  if(minutes === 60){ 
    add.mouseup();  ///<<<<<<<<<< release the mouse button hold
    add.disabled = true;
  }
@AmitP88
Nazar
@IsaakNazar
Apr 01 2018 15:56
@Aniculaesei id = "first" href please without space, `
Markus Kiili
@Masd925
Apr 01 2018 15:57
@Aniculaesei Space here k.com/"id = -> k.com/" id =
Amit Patel
@AmitP88
Apr 01 2018 16:00
@moigithub I see
Aniculaesei
@Aniculaesei
Apr 01 2018 16:03
@Masd925 I am sory...but still not works nothing :(
https://codepen.io/Aniculaesei/pen/RMyyLP
Moisés Man
@moigithub
Apr 01 2018 16:05

if u write alert("boo") inside ur load function.. it doesnt get called @Aniculaesei

document.onload = function(){
        var el =document.getElementById("first");
        el.href ="https://www.linkedin.com";
   alert("boo") ; //<<<<<<<
}

means it never gonna change the href

Aniculaesei
@Aniculaesei
Apr 01 2018 16:06
@moigithub but why? :)
@moigithub sorry
i now see the problem :D
window.onload
:)))
Moisés Man
@moigithub
Apr 01 2018 16:07
:D
Aniculaesei
@Aniculaesei
Apr 01 2018 16:08
@moigithub thanks
CamperBot
@camperbot
Apr 01 2018 16:08
aniculaesei sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
Nazar
@IsaakNazar
Apr 01 2018 16:08
@Aniculaesei
you can create function
function changeUrl(){
        var el = document.getElementById("first");
        el.innerHTML = "Linkedin";
    el.setAttribute('href', "http://linkedin.com");

    }
CamperBot
@camperbot
Apr 01 2018 16:08
:star2: 3735 | @moigithub |http://www.freecodecamp.org/moigithub
Nazar
@IsaakNazar
Apr 01 2018 16:09
@Aniculaesei and change your <a>, and when you click to First you will open new tab
<a onclick="changeUrl()" target="_blank" href="https://www.facebook.com/" id="first">First</a>
Aniculaesei
@Aniculaesei
Apr 01 2018 16:09
@IsaakNazar thank you :)
CamperBot
@camperbot
Apr 01 2018 16:09
aniculaesei sends brownie points to @isaaknazar :sparkles: :thumbsup: :sparkles:
:cookie: 322 | @isaaknazar |http://www.freecodecamp.org/isaaknazar
Nazar
@IsaakNazar
Apr 01 2018 16:10
@Aniculaesei :+1:
LuisHerasme
@LuisHerasme
Apr 01 2018 21:36
Hi
Tiago Correia
@tiagocorreiaalmeida
Apr 01 2018 21:36
hey
LuisHerasme
@LuisHerasme
Apr 01 2018 21:36
Would you make me a favor?
Tiago Correia
@tiagocorreiaalmeida
Apr 01 2018 21:37
sure, why not
LuisHerasme
@LuisHerasme
Apr 01 2018 21:37
Could you give me an star in this project so I reach the 200 stars and upload the project to cdnjs?
Tiago Correia
@tiagocorreiaalmeida
Apr 01 2018 21:38
not directly but will give a look on it and if I like it or find it usefull will do it for sure
LuisHerasme
@LuisHerasme
Apr 01 2018 21:40
Thank you anyway
alpox
@alpox
Apr 01 2018 22:12
@LuisHerasme Pls be a good one and name a Polygon Polygon and not Poligon :D
Stephen James
@sjames1958gm
Apr 01 2018 22:34
@LuisHerasme I starred your page, IMO I think you need more text on why someone should use your library.