These are chat archives for FreeCodeCamp/HelpJavaScript

25th
Feb 2018
FlashHero
@FlashHero
Feb 25 2018 00:10
@bradtaniguchi thanks I was trying to use bootstrap with react
Ken Haduch
@khaduch
Feb 25 2018 04:49
@AbrisM - your post :point_up: February 24, 2018 2:32 PM is a good example of how you need to use the code posting markdown syntax to post code. The * is interpreted by markdown for italicizing text, so you need to post with a block of code that has a single line with ``` at the top, and ``` at the bottom, that way your code will be displayed without those special interpretations of things that also happen to be meaningful in the markdown translation.
Zunaid Aslam
@ZunaidAslam
Feb 25 2018 11:28

Hello guys,
I was doing the weather project and I am having some issue with showing the values.

I used the html for my location eg. New York, Usa :

 <p id="city"> <span id="country"></span> </p>

Used Jquery to put the value

$('#city').text(city);
 $('#country').text(", "+ country);

The issue is it only shows the City not the country. But instead of span, if I use div then it shows both but obviously in next line in other words I need to add more CSS.

 <p id="city"> <div id="country"></div> </p>

I used Div in all places it's same as my first Html, only showing city.

Why is this happening? How can I put two values in a paragraph.
I am using span and putting the values of both city + country inside because then I can style/css the country.


 $('#city').text(city ", "+ country);

For some reason this messes up the style. Country

Greg Duncan
@GregatGit
Feb 25 2018 11:38
@FlashHero when using react with webpack or CRA you don't need to install bootstap as a dependency - just make sure the your main html file (index.html) has it as a link
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 11:39
@Zunaid-Aslam text(city ", "+ country); is straight up syntax error. It should be text(city + ", "+ country);
Zunaid Aslam
@ZunaidAslam
Feb 25 2018 11:40
Sorry, last one I typed wrong
But I was having trouble with the p and span version
I am styling Country differently so put it inside a span with an ID
And tried putting the values using simple jquery...but for some reason it's ignoring the span. It is only working with p tag
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 11:42
@Zunaid-Aslam Do you have it on codepen when I can take a look?
Zunaid Aslam
@ZunaidAslam
Feb 25 2018 11:43
I haven't put it in code pen yet
I will put it but at the moment I feel my code is quite messy not for humans lol. But I will still put it for you to test
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 11:45
:+1:
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 11:54
@Zunaid-Aslam If I understood correctly, you want to display city name followed by country?
Zunaid Aslam
@ZunaidAslam
Feb 25 2018 11:56
yup
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 11:56
The problem is not that span doesn't work inside p tag
Zunaid Aslam
@ZunaidAslam
Feb 25 2018 11:56
but i will style country differently
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 11:56
you have to do
<p>
  <span id="city"></span>
  <span id="country"></span>
</p>
Zunaid Aslam
@ZunaidAslam
Feb 25 2018 11:56
So, is it like P is overwriting the span value.
If i put the value of city inside p class
Let me test it :)
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 11:57

Your original markup was

 <p id="city">
  <span id="country"></span>
</p>

Then you do $('#city').text(city); Which causes your markup to change to

 <p id="city">
  Some City
</p>
Zunaid Aslam
@ZunaidAslam
Feb 25 2018 11:58
yeah
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 11:58
and then when you do $('#country').text(", "+ country); the element #country is no where to be found
Zunaid Aslam
@ZunaidAslam
Feb 25 2018 11:58
Your suggestion works thanks
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 11:58
:+1:
Zunaid Aslam
@ZunaidAslam
Feb 25 2018 11:58
But if I understand correctly if I put span inside p and target both. It basically targets the P
Thank you again for the help @SweetCodingInc
CamperBot
@camperbot
Feb 25 2018 11:59
zunaid-aslam sends brownie points to @sweetcodinginc :sparkles: :thumbsup: :sparkles:
:cookie: 309 | @sweetcodinginc |http://www.freecodecamp.org/sweetcodinginc
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 12:00
Nope. It targets them individually... However, since you change the parent p before you access the child #country, the country gets removed. So it just appears that it targets the parent (p) but in in reality it targets both individually
@Zunaid-Aslam You're welcome
Zunaid Aslam
@ZunaidAslam
Feb 25 2018 12:38
hmm, I tried targeting country with jquery first and then city keeping the same code but still doesn't work. The span issue worked though.
Zunaid Aslam
@ZunaidAslam
Feb 25 2018 13:16

I fixed one issue now stuck with another. As you helped me before easily this is why I am asking you again @SweetCodingInc . Why isn't my temperature changing?

used the code to test change :

  $("#changeT").click(function () {
      if ("#temperature"==tempc) {
      $('#temperature').text(tempF + String.fromCharCode(176));
  }
});

Codepen : https://codepen.io/Zunaid/pen/YeOgJP

I tried id changeT with anchor tag first, didn't work. And so used span. Still not working
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 13:36
@Zunaid-Aslam Let me check
I don't see that code in your pen @Zunaid-Aslam
can you add it?
Zunaid Aslam
@ZunaidAslam
Feb 25 2018 13:44
Done
@SweetCodingInc I missed somehow
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 13:47
@Zunaid-Aslam YOu need to compare value in #temperature
like if ($("#temperature").text() == tempC) {
and it's tempC not tempc
There is another problem, that you also have that degree symbol in the text
so the comparison would not work

First change this part

<p class="degree">
  <span id="temperature"></span>
  <span id="unit">C</span>
</p>

to

<p class="degree">
  <span id="temperature"></span>
  <span id="symbol"></span>
  <span id="unit">C</span>
</p>
Zunaid Aslam
@ZunaidAslam
Feb 25 2018 13:51
Will changing it work? Plus shouldn't my mouse arrow change when near
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 13:51

Then in js change

$('#temperature').text(tempC + String.fromCharCode(176));

to

$('#symbol').text(String.fromCharCode(176));
$('#temperature').text(tempC);
Zunaid Aslam
@ZunaidAslam
Feb 25 2018 13:53
Ok, I will fix that. But when I hover over the changeT shouldn't my mouse change to a click option
Here it doesn't. Ok let me change and test things out first
Thank you again @SweetCodingInc
CamperBot
@camperbot
Feb 25 2018 13:53
zunaid-aslam sends brownie points to @sweetcodinginc :sparkles: :thumbsup: :sparkles:
:cookie: 311 | @sweetcodinginc |http://www.freecodecamp.org/sweetcodinginc
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 13:56
And then
var $temp = $("#temperature");
var $unit = $('#unit');
$("#changeT").click(function () {
  var val = $temp.text();
  var uni = $unit.text();
  $temp.text(val == tempC ? tempF : tempC);
  $unit.text(uni === 'C' ? 'F' : 'C');
});
Zunaid Aslam
@ZunaidAslam
Feb 25 2018 14:27
 $temp.text(val == tempC ? tempF : tempC);
  $unit.text(uni === 'C' ? 'F' : 'C');
What does this mean?
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 14:29
@Zunaid-Aslam It's same as
if(val == tempC){
  $temp.text(tempF);
} else {
  $temp.text(tempC);
}

if(uni === 'C'){
  $unit.text('F');
} else {
  $unit.text('C');
}
It's called ternary operator
Zunaid Aslam
@ZunaidAslam
Feb 25 2018 14:30
It seems i need supplementary books and tutorials
in addition to freecodecamp
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 14:30
@Zunaid-Aslam This is not jquery
just alternate javascript syntax
Zunaid Aslam
@ZunaidAslam
Feb 25 2018 14:30
I understand
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 14:31
FCC does have a ternary challenge, I think
Zunaid Aslam
@ZunaidAslam
Feb 25 2018 14:31
In the original one or beta?
Maybe I forgot.
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 14:31
Original.. I haven't checked beta yet
Zunaid Aslam
@ZunaidAslam
Feb 25 2018 14:32
I guess i forgot. Thank you for your time @SweetCodingInc
CamperBot
@camperbot
Feb 25 2018 14:32
zunaid-aslam sends brownie points to @sweetcodinginc :sparkles: :thumbsup: :sparkles:
api offline
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 14:32
@Zunaid-Aslam :+1:
Aditya Sheth
@fantome149_twitter
Feb 25 2018 14:34
var numbers = [5, 6, 2, 3, 7];

var max = Math.max.apply(null, numbers);
console.log(max);

// expected output: 7
can someone explain why are we giving first parameter as null?
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 14:36
@fantome149_twitter the .apply expects first argument to be the context for execution. Since you're calling max.apply, the first argument would represent value of thiswithin max function.. But for finding max number, the this is not required to be set to any specific value.
So to circumvent that requirement of first parameter being context, we pass in null
Aditya Sheth
@fantome149_twitter
Feb 25 2018 14:38
can you give an example where we use this within max function and not give it as null
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 14:38
you can pass in any other value, it will still work as expected.
All valid
var max = Math.max.apply(null, numbers);
var max = Math.max.apply(undefined, numbers);
var max = Math.max.apply({}, numbers);
var max = Math.max.apply(Math, numbers);
var max = Math.max.apply(console, numbers);
var max = Math.max.apply(numbers, numbers);
@fantome149_twitter That's the whole point. We don't need to use thison .max function. that's we set it to null
bottom line is Math.max.apply(numbers) will not work. If you're using apply, the actual array has to be a second parameter.
But this will work
var numbers = [5, 6, 2, 3, 7];

var max = Math.max(...numbers);
console.log(max);
Aditya Sheth
@fantome149_twitter
Feb 25 2018 14:50
okay got it, thanks :smile:
@SweetCodingInc
Sweet Coding :)
@SweetCodingInc
Feb 25 2018 15:40
@fantome149_twitter :+1:
Aditya Sheth
@fantome149_twitter
Feb 25 2018 17:35
<body>

<p>The highest number is <span id="demo"></span>.</p>

<script>
var points = [40, 100, 1, 5, 25, 10];
document.getElementById("demo").innerHTML = myArrayMax(points);

function myArrayMax(arr) {
    var len = arr.length
    var max = -Infinity;
    while (len--) {
      if (arr[len] > max) {
        max = arr[len];
      }
    }
    return max;
}
</script>

</body>
This function loops through an array comparing each value with the highest value found
Can someone explain 1)why are we decreasing value of len 2)Why max is initialized to -Infinity
Markus Kiili
@Masd925
Feb 25 2018 17:41
@fantome149_twitter len is an index that loops array indices in reverse order. max is initialized to -Infinity because any number is greater than it. That code not very readable imo.
Aditya Sheth
@fantome149_twitter
Feb 25 2018 17:45
@Masd925 do you know any other way to solve it?
I was referring this snippet
Nicole F.
@gitasong
Feb 25 2018 18:02
Hello, All. I can't seem to get the regex right in the Palindrome exercise. I remember there was a trick to it.
Mr. Frosty
@BinaryKing
Feb 25 2018 18:07
@fantome149_twitter what are you trying to do?
@fantome149_twitter len-- I imagine does not work in your while loop
Aditya Sheth
@fantome149_twitter
Feb 25 2018 18:08
I think I got an alternative method
var array = [3, 4, 5, 21.15, 21, 9];
var largest = 0;

for (i = 0; i < array.length; i++) {
    if (array[i] > largest) {
        largest = array[i];
    }
}
console.log(largest);​
this makes more sense to me than that snippet
Mr. Frosty
@BinaryKing
Feb 25 2018 18:09
@fantome149_twitter You can also just do
function myArrayMax(arr) {
return Math.max(...arr)
}
Nicole F.
@gitasong
Feb 25 2018 18:10
@BinaryKing Will the editor accept ES6 syntax? It wouldn't when I tried.
Markus Kiili
@Masd925
Feb 25 2018 18:10
@fantome149_twitter That will not work with negative numbers. Initializing to -Infinity would make it work.
Mr. Frosty
@BinaryKing
Feb 25 2018 18:11
@gitasong ES6 is widely accepted now
Aditya Sheth
@fantome149_twitter
Feb 25 2018 18:11
@BinaryKing yeah that's also an method, but my objective is to compare each element with highest element
Nicole F.
@gitasong
Feb 25 2018 18:11
I'm referring to the FCC editor, @BinaryKing . Try it. :)
Mr. Frosty
@BinaryKing
Feb 25 2018 18:11
@fantome149_twitter Oh, yes I it does.
It will give a little error but the error doesn't matter when you run the code.
Nicole F.
@gitasong
Feb 25 2018 18:12
Ah; okay.
Mr. Frosty
@BinaryKing
Feb 25 2018 18:12
:)
Nicole F.
@gitasong
Feb 25 2018 18:13
It says something about using 'esversion: 6', but I couldn't figure out where to put that. Is it like 'use strict'?
Mr. Frosty
@BinaryKing
Feb 25 2018 18:13
I would never think to put while(len--)
Im trying to understand how that works?
Nicole F.
@gitasong
Feb 25 2018 18:13
Yeah—that doesn't make a lot of sense to me, either. While len keeps decrementing? That seems like a recipe for disaster.
Mr. Frosty
@BinaryKing
Feb 25 2018 18:14
It somehow works.
Nicole F.
@gitasong
Feb 25 2018 18:14
Really?
Mr. Frosty
@BinaryKing
Feb 25 2018 18:14
Thanks Javascript
For the confusion
:rage:
Nicole F.
@gitasong
Feb 25 2018 18:14
JS is so annoying. :)
Mr. Frosty
@BinaryKing
Feb 25 2018 18:15
Yes, it give the correct answer. In the array he gave
But I don't think it will work in all cases
Nicole F.
@gitasong
Feb 25 2018 18:15
That's weird. No; definitely not.
Mr. Frosty
@BinaryKing
Feb 25 2018 18:15
Like
When would len-- ever be false?
Nicole F.
@gitasong
Feb 25 2018 18:16
Well, exactly. So you're basically saying while (true), which is unfalsifiable, so you'd get an endless loop.
On the other hand, while (arr.len--) might terminate when arr.len gets to 0.
Anyhoo, does anyone know the answer to my Palindrome question? I can't seem to get the regex right. I remember there was a trick to it. (I'm re-doing the Basic Algorithms.)
Mr. Frosty
@BinaryKing
Feb 25 2018 18:18
So maybe it read len-- as if arr.len? I guess that wouldn't make sense but its Javascript so....who knows :laughing:
Nicole F.
@gitasong
Feb 25 2018 18:18
See my comment above.
Mr. Frosty
@BinaryKing
Feb 25 2018 18:18
Oh sorry hehe
Nicole F.
@gitasong
Feb 25 2018 18:18
Beat you to it. :)
Aditya
@ezioda004
Feb 25 2018 18:18
I think you can put /*jshint esversion: 6 */ at top of your code and it will recognize es6 syntax.
Nicole F.
@gitasong
Feb 25 2018 18:19
Ah! Thanks, @ezioda004 !
CamperBot
@camperbot
Feb 25 2018 18:19
gitasong sends brownie points to @ezioda004 :sparkles: :thumbsup: :sparkles:
:cookie: 479 | @ezioda004 |http://www.freecodecamp.org/ezioda004
Mr. Frosty
@BinaryKing
Feb 25 2018 18:19
@gitasong Are you trying to get rid of all none alphanumeric chars?
@ezioda004 You can but you don't need to. :)
Nicole F.
@gitasong
Feb 25 2018 18:19
Yep. I remember there was a trick to it. A bunch of the tests don't pass with /\W/.
Mr. Frosty
@BinaryKing
Feb 25 2018 18:20
Seems to work with out it
Aditya
@ezioda004
Feb 25 2018 18:20
True, but just in case.
Nicole F.
@gitasong
Feb 25 2018 18:21
But then when I start adding stuff—e.g. /\W\s/, things get weird.
Mr. Frosty
@BinaryKing
Feb 25 2018 18:21
\w
Aditya
@ezioda004
Feb 25 2018 18:21
@gitasong What do you want match?
Nicole F.
@gitasong
Feb 25 2018 18:21
I want to replace the unwanted characters.
Mr. Frosty
@BinaryKing
Feb 25 2018 18:22
What is \s?
Nicole F.
@gitasong
Feb 25 2018 18:22
I want to match all non-alphanumerics.
Aditya
@ezioda004
Feb 25 2018 18:22
whitespace
Nicole F.
@gitasong
Feb 25 2018 18:22
Yep.
Mr. Frosty
@BinaryKing
Feb 25 2018 18:22
Oh ok hehe don't have my cheatsheet open :P
Mr. Frosty
@BinaryKing
Feb 25 2018 18:23
wouldn't just string.replace(/\w/g, '') do the trick?
Nicole F.
@gitasong
Feb 25 2018 18:23
\w are alphanumerics. I want to keep those.
Mr. Frosty
@BinaryKing
Feb 25 2018 18:24
or W
Nicole F.
@gitasong
Feb 25 2018 18:24
That's what I used. It doesn't work.
But I forgot the g tag, so hold on...
Mr. Frosty
@BinaryKing
Feb 25 2018 18:24
Sorry I don't have meta chars saved in my memory :(
I usually use a cheatsheet :)
Nicole F.
@gitasong
Feb 25 2018 18:25
Did you see my link?
Aditya
@ezioda004
Feb 25 2018 18:25
/[\W_]/g
Mr. Frosty
@BinaryKing
Feb 25 2018 18:25
^^ there you go
Whats the underscore?
Nicole F.
@gitasong
Feb 25 2018 18:25
Ah! That was it. Thanks, @ezioda004 !
CamperBot
@camperbot
Feb 25 2018 18:25
gitasong sends brownie points to @ezioda004 :sparkles: :thumbsup: :sparkles:
api offline
Aditya
@ezioda004
Feb 25 2018 18:25
Nicole F.
@gitasong
Feb 25 2018 18:25
Underscore.
Kelechi Chinaka
@ke1echi
Feb 25 2018 18:25
/[^a-z0-9]/gi @gitasong
Nicole F.
@gitasong
Feb 25 2018 18:25
Ah, yeah—I knew there was another one.
Thanks, @kelechy !
CamperBot
@camperbot
Feb 25 2018 18:26
gitasong sends brownie points to @kelechy :sparkles: :thumbsup: :sparkles:
:cookie: 326 | @kelechy |http://www.freecodecamp.org/kelechy
Aditya
@ezioda004
Feb 25 2018 18:26
Underscore misses \W @BinaryKing
Mr. Frosty
@BinaryKing
Feb 25 2018 18:26
@ezioda004 I see, thanks!
CamperBot
@camperbot
Feb 25 2018 18:26
binaryking sends brownie points to @ezioda004 :sparkles: :thumbsup: :sparkles:
:cookie: 480 | @ezioda004 |http://www.freecodecamp.org/ezioda004
Nicole F.
@gitasong
Feb 25 2018 18:26
So why does /W need to be in square brackets, @ezioda004 ?
Mr. Frosty
@BinaryKing
Feb 25 2018 18:28
gets all matches
??
Aditya
@ezioda004
Feb 25 2018 18:28
Cause we have _ too multiple regex needs to be inside [ ]
Nicole F.
@gitasong
Feb 25 2018 18:28
"multiple regex"?
You mean matching multiple patterns?
Aditya
@ezioda004
Feb 25 2018 18:29
Yes multiple patterns*
Nicole F.
@gitasong
Feb 25 2018 18:30
Or patterns that involve multiple characters? (Multiple characters in the regex, not necessarily in the result, like [a-f], etc.)
Aditya Sheth
@fantome149_twitter
Feb 25 2018 18:31
@Masd925 I guess 2nd method is working for -ve Values also, I just checked it again.
Nicole F.
@gitasong
Feb 25 2018 18:31
In other words, if you wrote /a-f/, it would take those characters literally (well, sort of, since the - character's not escaped).
Anyway, this should pass. Thanks, all!
Yeah—I don't nee the whole answer, @BinaryKing .
Mr. Frosty
@BinaryKing
Feb 25 2018 18:32
I thought you were done?
Nicole F.
@gitasong
Feb 25 2018 18:32
Nope.
Mr. Frosty
@BinaryKing
Feb 25 2018 18:32
sorry
I delete
Nicole F.
@gitasong
Feb 25 2018 18:32
I'm just saying that the regex should work.
:)
Mr. Frosty
@BinaryKing
Feb 25 2018 18:32
Oh I see
:)
Nicole F.
@gitasong
Feb 25 2018 18:32
:)
Anyhoo, it's trivial from here. The regex was the hard part.
Aditya Sheth
@fantome149_twitter
Feb 25 2018 18:34
@BinaryKing could you verify whether 2nd method which I posted earlier works with -ve values also.
For me it's working
Mr. Frosty
@BinaryKing
Feb 25 2018 18:34
@fantome149_twitter Looks good to me.
second one looks good to me
Aditya Sheth
@fantome149_twitter
Feb 25 2018 18:36
@Masd925 says it won't work with -ve values, we have to initialize it to -Infinity
anyways got it.
Daniel Romero
@Ranacode
Feb 25 2018 19:56
Hey I have weird issue with nextjs
The layout content is not rendered on my page
import Head from 'next/head';

const Layout = (props) => {
    return (
        <div>
            <Head>
                <meta name="viewport" content="width=device-width, initial-scale=1" key="viewport" />
                <meta charSet="utf-8" key="utf" />
                <title>Javascrupt - Lleva tus habilidades de Javascript al siguiente nivel</title>
                <link
                    href="https://fonts.googleapis.com/css?family=Raleway|Lusitana"
                    rel="stylesheet"
                    key="globalFonts"
                />
            </Head>
            {props.children}

            <style jsx global>{`
                body {
                    background: #fafafa;
                    font-family: Raleway, Helvetica Neue, Helvetica, Arial, sans-serif;
                    color: #fff;
                }
            `}</style>
        </div>
    );
};

export default Layout;
import Layout from '../components/Layout/Layout';
const Index = (props) => {
    return (
        <Layout>
            <h3>Soy el contenido del layout</h3>
        </Layout>
    );
};

export default Index;
but there are no errors on neither, browser and server console
Daniel Romero
@Ranacode
Feb 25 2018 20:09
LOL NO WORRIES, I was using a blank font color so I couldn't see the letters xD
alpox
@alpox
Feb 25 2018 20:39
@Ranacode Classic :laughing:
I've seen people use white text on white to fake some formatting xD
Daniel Romero
@Ranacode
Feb 25 2018 20:57
ye :P
are you still here?
alpox
@alpox
Feb 25 2018 20:58
yep
Daniel Romero
@Ranacode
Feb 25 2018 20:58
I'm trying to positioning an icon inside a li element in the bottom right corner
but I can't achieve it with the parent container with relative position and the child with absolute
alpox
@alpox
Feb 25 2018 20:58
Lemme se
Which one of those clocks? :D
Daniel Romero
@Ranacode
Feb 25 2018 20:59
lol this codepen is buggy
I'm seeing a lot of bells around the page
and I have only one <i>
alpox
@alpox
Feb 25 2018 21:00
yea pretty buggy xD
<i class="fa fa-bell" />--> <i class="fa fa-bell" ></i>
Works
Daniel Romero
@Ranacode
Feb 25 2018 21:01
ou shit right I just copied from jsx
Ok the thign I want is put the bell icon in the bottom right corner
alpox
@alpox
Feb 25 2018 21:01
Hmm that icon looks positioned nicely. You want it in the bottom right corner though?
Daniel Romero
@Ranacode
Feb 25 2018 21:01
Yeah, I want to see if worth it
Doesn't look any good, but its right bottom xD
Daniel Romero
@Ranacode
Feb 25 2018 21:05
thanks @alpox
CamperBot
@camperbot
Feb 25 2018 21:05
ranacode sends brownie points to @alpox :sparkles: :thumbsup: :sparkles:
:star2: 1555 | @alpox |http://www.freecodecamp.org/alpox
Daniel Romero
@Ranacode
Feb 25 2018 21:05
bah, its ugly in that corner
I think inline is o
ok
alpox
@alpox
Feb 25 2018 21:07
I think so too :D
FlashHero
@FlashHero
Feb 25 2018 21:58
@GregatGit thanks
CamperBot
@camperbot
Feb 25 2018 21:58
flashhero sends brownie points to @gregatgit :sparkles: :thumbsup: :sparkles:
:cookie: 896 | @gregatgit |http://www.freecodecamp.org/gregatgit
Jefferson
@jeffersonnnn
Feb 25 2018 22:34

hi guys, i need help getting a proper read on this syntax. I am trying to select a random element in an array. Here is my code

 handlePick() {
    this.setState(() => {
      return {
        this.state.options[Math.floor(Math.random()*options.length)]
      }; 
    });
  }
    this.state = {
       options: ['Thing one', 'Thing two', 'Thing three']
    };
  }

right up above here is the array

any help, please?
Stephen James
@sjames1958gm
Feb 25 2018 22:52
@jeffersonnnn Which state property are you trying to set to the random value?
@jeffersonnnn Look on the other channel - alpox has a handle on it