These are chat archives for FreeCodeCamp/HelpJavaScript

24th
Aug 2017
Stephen James
@sjames1958gm
Aug 24 2017 00:58
@Slitherings And where would you store this list of strings? Perhaps in an array?
Joseph
@revisualize
Aug 24 2017 01:21
@sjames1958gm :wave:
Pagnito
@Pagnito
Aug 24 2017 01:31
can i define event handlers in child componenets in react?
hmm nvm, must something else im doing wrong
Greg Duncan
@GregatGit
Aug 24 2017 01:34
@Pagnito yes - but not if they alter the state of the parent - then they need to passed down
Pagnito
@Pagnito
Aug 24 2017 01:34
@GregatGit k thanks, i seem to having trouble where my child component is just not handling events at all
CamperBot
@camperbot
Aug 24 2017 01:34
pagnito sends brownie points to @gregatgit :sparkles: :thumbsup: :sparkles:
:cookie: 882 | @gregatgit |http://www.freecodecamp.com/gregatgit
Pagnito
@Pagnito
Aug 24 2017 01:35
import React from 'react'



const RecipeList = (props) => {


  function expand(){
    console.log('wtf')
  }


    return (
      <div  id="recipeList">
        <ul className="collapsible" data-collapsible="expandable">
            <li>
            <div onClick={expand} className="collapsible-header"><i className="material-icons">filter_drama</i>First</div>
            <div className="collapsible-body"><span>Lorem ipsum dolor sit amet.</span></div>
            </li>
            <li>
            <div className="collapsible-header"><i className="material-icons">place</i>Second</div>
            <div className="collapsible-body"><span>Lorem ipsum dolor sit amet.</span></div>
            </li>
            <li>
            <div className="collapsible-header"><i className="material-icons">whatshot</i>Third</div>
            <div className="collapsible-body"><span>Lorem ipsum dolor sit amet.</span></div>
            </li>
          </ul>
      </div>
    )


}

export default RecipeList

import React from 'react'
import ReactDOM from 'react-dom'
import Header from './components/header.js'
import RecipeList from './components/recipeList.js'
import $ from 'jquery'

console.log('wtf')
var getElement = (query) => {
return document.querySelector(query);
}

class App extends React.Component {
constructor(props){
super(props)
this.state={

}

}

render(){

return(
  <div>
    <Header />
    <RecipeList  />
  </div>
)

}
}

ReactDOM.render(<App />, getElement('.container'))

```

import React from 'react'
import ReactDOM from 'react-dom'
import Header from './components/header.js'
import RecipeList from './components/recipeList.js'
import $ from 'jquery'

console.log('wtf')
var getElement = (query) => {
  return document.querySelector(query);
}


class App extends React.Component {
  constructor(props){
    super(props)
    this.state={

    }

  }


  render(){

    return(
      <div>
        <Header />
        <RecipeList  />
      </div>
    )
  }
}

ReactDOM.render(<App />, getElement('.container'))
Stephen James
@sjames1958gm
Aug 24 2017 01:37
@revisualize :wave: How's the wrist these days?
@Pagnito Where are you defining handlers?
Pagnito
@Pagnito
Aug 24 2017 01:39
@sjames1958gm in the RecipeList
Greg Duncan
@GregatGit
Aug 24 2017 01:39
@Pagnito First - you shouldn't be using jQuery in React - try to avoid it
Stephen James
@sjames1958gm
Aug 24 2017 01:39
I just saw.
Greg Duncan
@GregatGit
Aug 24 2017 01:39
@Pagnito A friend gave me a simple example on how send functions down the line
const A = ({ aImportantMsg, aHandleChange }) => (
  <div>
    <input type='text' onChange={aHandleChange} />
    {aImportantMsg}
  </div>
)

const B = ({ importantMsg, handleChangeValue }) => (
  <A aImportantMsg={importantMsg} aHandleChange={handleChangeValue} />
)

class C extends React.Component {
  constructor () {

    state = {
      AValue: ''
    }
  }

  handleAValueChange (e) {
    this.setState({ AValue: e.target })
  }

  render () {

    return (
      <div>
        <B importantMsg={AValue} handleChangeValue={handleAValueChange}
      </div>
    )
  }
}
Pagnito
@Pagnito
Aug 24 2017 01:39
@GregatGit yea but i need it form materialize
Stephen James
@sjames1958gm
Aug 24 2017 01:39
@Pagnito I assume that "wtf" is not coming to the console onCLick?
Pagnito
@Pagnito
Aug 24 2017 01:40
@sjames1958gm yea
and even if i pass the function from parent it doenst work
Greg Duncan
@GregatGit
Aug 24 2017 01:40
@Pagnito do you have this on github?
Pagnito
@Pagnito
Aug 24 2017 01:40
i made the same thing in codepen and it works
no, but hold on ill put it on and give u the link
Stephen James
@sjames1958gm
Aug 24 2017 01:42
@Pagnito Don't you need expand() calling the function?
Pagnito
@Pagnito
Aug 24 2017 01:42
ifi u se {expand()} it gets called without click
Stephen James
@sjames1958gm
Aug 24 2017 01:43
@Pagnito duh, sorry :(
Pagnito
@Pagnito
Aug 24 2017 01:43
np hehe
but yea take a look at the repo, hopefully ull find some thing :/ ive been on this shit for hours T.T
Stephen James
@sjames1958gm
Aug 24 2017 01:44
@Pagnito Any errors in the console?
Pagnito
@Pagnito
Aug 24 2017 01:45
nop
@GregatGit btw even i dont use jquery and materialize i still seem to have this problem
Moisés Man
@moigithub
Aug 24 2017 01:48
nvm
Stephen James
@sjames1958gm
Aug 24 2017 01:49
@moigithub I was thinking the same at first
Moisés Man
@moigithub
Aug 24 2017 01:49
yea didnt saw its not a class
Stephen James
@sjames1958gm
Aug 24 2017 01:57
@Pagnito Are you sure there are no compile errors?
Pagnito
@Pagnito
Aug 24 2017 01:57
positive
it compiles an everything
and everything displays
just doesnt function
Stephen James
@sjames1958gm
Aug 24 2017 02:01
hmm
Pagnito
@Pagnito
Aug 24 2017 02:03
the weird thing is, if i define an event handler in the parent component and put onClick on to the renderin div it works
if i pass it to the child it doesnt
Greg Duncan
@GregatGit
Aug 24 2017 02:05
@Pagnito try onClick={expand()}
Pagnito
@Pagnito
Aug 24 2017 02:05
i did
it just executes on render
and even after than it doesnt work onClick
juni
@junipberry
Aug 24 2017 02:06
hey guys, why does this not work?
function addToFront(arr, element) {
  return arr.unshift(element);
}
Gersho
@Gersho
Aug 24 2017 02:07
try arr.unshift(element);
return arr;
(on 2 lines)
Claudio Restifo
@Marmiz
Aug 24 2017 02:07

@Pagnito haven't seen the whole conversation, but are you sure you are binding this the correct way?

sometimes in an action you need to define a function that calls your function:

onClick={ (e) => this.props.clickActionDefined(e) }
Pagnito
@Pagnito
Aug 24 2017 02:08
im not passing the handler from parent
John
@AnonymousLords
Aug 24 2017 02:09
Guys im still confused on this
IndexOf()
'Blue Whale'.indexOf('', 9); // returns 9
Why is this>
Moisés Man
@moigithub
Aug 24 2017 02:10

adding a set of () will immediatelly call the function @Pagnito
im not sure what child u talking about

if i pass it to the child it doesnt

John
@AnonymousLords
Aug 24 2017 02:10
Is it because from 0 to the 9th (10th) chacater theirs 9 (10) chacacters).
Gersho
@Gersho
Aug 24 2017 02:10
@AnonymousLords If searchValue is an empty string, the behaviour is as follows — if fromIndex < str.length, fromIndex is returned; if fromIndex >= str.length, str.length is returned.
Stephen James
@sjames1958gm
Aug 24 2017 02:10
@AnonymousLords I am guessing if you pass an empty string to indexOf it finds the strings immediately
John
@AnonymousLords
Aug 24 2017 02:11
IUt finds the string length?
'Blue Whale'.indexOf('Whale', 7); // returns -1
?
Gersho
@Gersho
Aug 24 2017 02:11
but i don't really understand why we would want to search the index of an empty string, but if you're confused, try it with something else than a empty string
Pagnito
@Pagnito
Aug 24 2017 02:11
@moigithub yea i know about the (), what i was saying, was that even if i define the handler in the root parent js component and pass it to recipelist, it still doesnt work
Gersho
@Gersho
Aug 24 2017 02:11
-1 means not found
Claudio Restifo
@Marmiz
Aug 24 2017 02:11

@Pagnito so you have two "options"
you either bind this

  constructor(props){
    super(props);

    this.action= this.action.bind(this);
  }

action() {
 // do something
}

<Button onClick={this.action()} />

Or again you call a function that calls your function:

action() {
 // do something
}

<Button onClick={() => this.action()} />
Stephen James
@sjames1958gm
Aug 24 2017 02:11
@AnonymousLords You are starting the search after Whale so it cannot find whale
John
@AnonymousLords
Aug 24 2017 02:11
Oh
'Blue Whale'.indexOf('Whale', 0); // returns 5
Pagnito
@Pagnito
Aug 24 2017 02:12
@Marmiz im not using a class, but i was before, and i did that and it didnt work
John
@AnonymousLords
Aug 24 2017 02:12
Why doe sit return 5
Is their 6 chacters from whale to the start of the string?
Stephen James
@sjames1958gm
Aug 24 2017 02:13
@AnonymousLords The index of W is 5 indexes start at 0
juni
@junipberry
Aug 24 2017 02:13
did it~ ty @Gersho
CamperBot
@camperbot
Aug 24 2017 02:13
junipberry sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 350 | @gersho |http://www.freecodecamp.com/gersho
Gersho
@Gersho
Aug 24 2017 02:13
@AnonymousLords index starts frol 0 like array
John
@AnonymousLords
Aug 24 2017 02:13
So the 'element"/ word is 5 chacaters from the start>
Gersho
@Gersho
Aug 24 2017 02:14
@AnonymousLords B = 0 l = 1 etc, so W = 5
Stephen James
@sjames1958gm
Aug 24 2017 02:14
@AnonymousLords W is the 6th letter at index 5
John
@AnonymousLords
Aug 24 2017 02:15
? @sjames1958gm
@Gersho i understand that
Gersho
@Gersho
Aug 24 2017 02:16
james said the same thing than me, so you can't understand me but ? him :p
Pagnito
@Pagnito
Aug 24 2017 02:16
@moigithub yea its weird cuz the one i did in codepen also works, but it wont work in my environemtn
John
@AnonymousLords
Aug 24 2017 02:16
Index 5 reallys means 6 right?
Pagnito
@Pagnito
Aug 24 2017 02:16
even if i pass the handler like u did
Stephen James
@sjames1958gm
Aug 24 2017 02:17
@AnonymousLords
B - index 0  first
l - index 1 second
u - index 2 third
e - index 3 fourth 
  - index 4 fifth
W - index 5 sixth
@AnonymousLords Index 5 means the 6th character. because 0 means the first character
John
@AnonymousLords
Aug 24 2017 02:18
Thanks @sjames1958gm @Gersho @sjames1958gm
CamperBot
@camperbot
Aug 24 2017 02:18
anonymouslords sends brownie points to @sjames1958gm and @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 351 | @gersho |http://www.freecodecamp.com/gersho
:star2: 8372 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Gersho
@Gersho
Aug 24 2017 02:18
@AnonymousLords like array, it starts at index 0
Claudio Restifo
@Marmiz
Aug 24 2017 02:18

@Pagnito I went into your repo and noticed that the click handler is on a Div. Can you please check that the div has an actual size on the page, when rendered?

(also side note, in general you don't want to commit in github the build folder.. it's just extra unecessary space)

John
@AnonymousLords
Aug 24 2017 02:19
@Gersho Okay it makes sense, i didnt understand teh difference their for a sec :P
Pagnito
@Pagnito
Aug 24 2017 02:19
@Marmiz yea it does, that was a test tho, i originally had on the ul list
@Marmiz thanks for the build tip tho haha
CamperBot
@camperbot
Aug 24 2017 02:19
pagnito sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1030 | @marmiz |http://www.freecodecamp.com/marmiz
Claudio Restifo
@Marmiz
Aug 24 2017 02:21
@Pagnito also try to remove the function delcaration:
 // instead of function expand(){
//try
  expand(){
    console.log('wtf')
  }


    return (
            <div onClick={this.expand} className="collapsible-header"><i className="material-icons">filter_drama</i>First</div>
            ... rest
    )
juni
@junipberry
Aug 24 2017 02:21
don’t know why this is not passing
function computeAreaOfARectangle(length, width) {
  return (2*(length*width));
}
Pagnito
@Pagnito
Aug 24 2017 02:22

@Marmiz

import React from 'react'



class RecipeList extends React.Component {
  constructor(props){
    super(props)
    this.expand = this.expand.bind(this)
  }

   expand(){
    console.log('wtf')
  }

  render() {
    return (
      <div  id="recipeList">
        <ul className="collapsible" data-collapsible="expandable">
            <li>
            <div  onClick={this.expand} className="collapsible-header"><i className="material-icons">filter_drama</i>First</div>
            <div className="collapsible-body"><span>Lorem ipsum dolor sit amet.</span></div>
            </li>
            <li>
            <div className="collapsible-header"><i className="material-icons">place</i>Second</div>
            <div className="collapsible-body"><span>Lorem ipsum dolor sit amet.</span></div>
            </li>
            <li>
            <div className="collapsible-header"><i className="material-icons">whatshot</i>Third</div>
            <div className="collapsible-body"><span>Lorem ipsum dolor sit amet.</span></div>
            </li>
          </ul>
      </div>
    )
  }

}

export default RecipeList

this is what i have now

Stephen James
@sjames1958gm
Aug 24 2017 02:22
@junipberry The area is just length*width (not times 2)
Pagnito
@Pagnito
Aug 24 2017 02:22
thats also what i orginially had
then i tried chaning to function component
juni
@junipberry
Aug 24 2017 02:22
lol oops
Stephen James
@sjames1958gm
Aug 24 2017 02:22
@junipberry :)
juni
@junipberry
Aug 24 2017 02:22
I was on another one w 3 times the area
mixed it up
lol ty @sjames1958gm
CamperBot
@camperbot
Aug 24 2017 02:23
junipberry sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8373 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Randy
@RandyGoldsmith
Aug 24 2017 02:25
i keep getting type error..could someone explain why my code is wrong?
function addCalculateDiscountPriceMethod(storeItem) {
  // add a method to the storeItem object called 'calculateDiscountPrice'
  // this method should multiply the storeItem's 'price' and 'discountPercentage' to get the discount
  // the method then subtracts the discount from the price and returns the discounted price
  // example: 
  // price -> 20
  // discountPercentage -> .2
  // discountPrice = 20 - (20 * .2)
  console.log(storeItem);
 storeItem.calculateDiscountPrice = function () {
 return this.price - (this.price * this.discountPercentage);
    };
}
Greg Duncan
@GregatGit
Aug 24 2017 02:27
@Pagnito i set up a small example that works fine
import React from 'react'

const FunctionButton = () => {
  function doit () {
    console.log('i did it')
  }
  return (
    <div>
      Testing
      <div onClick={doit}>click</div>
    </div>
  )
}

export default FunctionButton
Claudio Restifo
@Marmiz
Aug 24 2017 02:27
@Pagnito anyway you have to be aware of writing a function inside a stateless component. Your new function will be created (and thus called) every time your component re-renders.
Pagnito
@Pagnito
Aug 24 2017 02:27
@GregatGit yea i know, it works if i do it in my header, but some reason it wont in the recipeList
@Marmiz atm im back to using a class but it still doesnt work
Greg Duncan
@GregatGit
Aug 24 2017 02:29
@Pagnito try
expand = () => {
    console.log('wtf')
  }
Pagnito
@Pagnito
Aug 24 2017 02:30
@GregatGit i dunno why but using arrow function event handlers seems to break my build
Greg Duncan
@GregatGit
Aug 24 2017 02:30
or codepen
Pagnito
@Pagnito
Aug 24 2017 02:31
i have a copy that works in codepen so it really frustrating lol
Greg Duncan
@GregatGit
Aug 24 2017 02:31
are you using webpack?
Pagnito
@Pagnito
Aug 24 2017 02:31
yea
Randy
@RandyGoldsmith
Aug 24 2017 02:31
@sjames1958gm any comment?
Claudio Restifo
@Marmiz
Aug 24 2017 02:33
@Pagnito I set up a sandbox for you to test :)
https://codesandbox.io/s/qk7p241064
Stephen James
@sjames1958gm
Aug 24 2017 02:34
@Pagnito You need to add more compile options to your babel config in webpack.config.js
Pagnito
@Pagnito
Aug 24 2017 02:34
@sjames1958gm what do i need to add?
Stephen James
@sjames1958gm
Aug 24 2017 02:35
'es2015', 'stage-0' along with 'react' which should already be there
Randy
@RandyGoldsmith
Aug 24 2017 02:35
so if i have an object.. an?d i need to create a method on that object using a function.. why wont it let me use the dot notation
Greg Duncan
@GregatGit
Aug 24 2017 02:35
@Pagnito
// install dependencies
npm install --save-dev babel-plugin-transform-class-properties

// then add to webpack.config.js
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /(node_modules)/,
        loader: 'babel-loader',
        query: {
          presets: ['stage-0','es2015', 'react'],
          plugins: ["transform-class-properties"] // you add this line here
        }
      },

// and add this to your .babelrc (you will add to the other plugins not just paste all this
{
  "plugins": ["transform-class-properties"]
}
Stephen James
@sjames1958gm
Aug 24 2017 02:35
@RandyGoldsmith When you run this code? Is there more to the error?
Randy
@RandyGoldsmith
Aug 24 2017 02:36
{ price: 20, discountPercentage: 0.2 }
TypeError: Cannot set property 'calculateDiscountPrice' of undefined
    at addCalculateDiscountPriceMethod:17:36
    at eval:25:1
    at eval
    at n.<anonymous>
this is dueldrawer8 btw.. i had to change my github account due to some problems
Greg Duncan
@GregatGit
Aug 24 2017 02:36
@Pagnito i had the same problem - this is the key line plugins: ["transform-class-properties"] // you add this line here
Pagnito
@Pagnito
Aug 24 2017 02:37
@GregatGit what about stage-0 whats that?
Stephen James
@sjames1958gm
Aug 24 2017 02:37
@RandyGoldsmith You must be calling that function without a parameter
Claudio Restifo
@Marmiz
Aug 24 2017 02:37
@RandyGoldsmith mind that dot notation is litteral, so if you are passing a variable value you need square brackets:
var test = 'something'

myObject.test // will look for the key 'test'

myObject[test] // will look for key 'something'
Randy
@RandyGoldsmith
Aug 24 2017 02:37
var storeItem = {
  price: 20,
  discountPercentage: 0.2,
};

function addCalculateDiscountPriceMethod(storeItem) {
  // add a method to the storeItem object called 'calculateDiscountPrice'
  // this method should multiply the storeItem's 'price' and 'discountPercentage' to get the discount
  // the method then subtracts the discount from the price and returns the discounted price
  // example: 
  // price -> 20
  // discountPercentage -> .2
  // discountPrice = 20 - (20 * .2)

 storeItem.calculateDiscountPrice = function () {
 var discount = this.price * this.discountPercentage;
 console.log(this.price - discount);
    };
}
Stephen James
@sjames1958gm
Aug 24 2017 02:37
@RandyGoldsmith Where are you calling addCalculateDiscountPriceMethod
Randy
@RandyGoldsmith
Aug 24 2017 02:37
oh sorry
Greg Duncan
@GregatGit
Aug 24 2017 02:38
@Pagnito don't worry to much - have you considered using create-react-app for your project?
create-react-app is the bomb :bomb:
Randy
@RandyGoldsmith
Aug 24 2017 02:39
var storeItem = {
  price: 20,
  discountPercentage: 0.2,
};



function addCalculateDiscountPriceMethod(storeItem) {
  // add a method to the storeItem object called 'calculateDiscountPrice'
  // this method should multiply the storeItem's 'price' and 'discountPercentage' to get the discount
  // the method then subtracts the discount from the price and returns the discounted price
  // example: 
  // price -> 20
  // discountPercentage -> .2
  // discountPrice = 20 - (20 * .2)

 storeItem.calculateDiscountPrice = function () {
 var discount = this.price * this.discountPercentage;
 console.log(this.price - discount);
    };
}



addCalculateDiscountPriceMethod(storeItem.calculateDiscountPrice());
Pagnito
@Pagnito
Aug 24 2017 02:39
@GregatGit i couldnt install it locally plus i wnna be able to build my own boilerplates thats why im digging thru this shit lol
@GregatGit do i need to install stage-0 ?
Randy
@RandyGoldsmith
Aug 24 2017 02:40
@sjames1958gm first i need to add calculateDiscountPrice method to the storeItem object
Ginger
@GingerChew
Aug 24 2017 02:40
I'm getting an error message in the terminal saying I've exceeded the maximum call stack size? is it my code?
function addTogether() {
  var arg = 0, addToTwo = addTogether(arguments[0]);
  for (var i in arguments) {
    if (typeof arguments[i] == 'number') {
      arg += arguments[i];
    } else if (typeof arguments[i] == 'string') {
      return undefined;
    }
  }
  return arg;
}
Randy
@RandyGoldsmith
Aug 24 2017 02:40
@sjames1958gm then i need it to do something
Stephen James
@sjames1958gm
Aug 24 2017 02:41
@RandyGoldsmith addCalculateDiscountPriceMethod
that code to add that is inside ^^ this function so you must call it somewhere?
Greg Duncan
@GregatGit
Aug 24 2017 02:41
@Pagnito just try those webpack changes I've shown
Stephen James
@sjames1958gm
Aug 24 2017 02:42
@GingerChew You are calling the function from inside the function addTogether(arguments[0]); infinite recursion
Pagnito
@Pagnito
Aug 24 2017 02:42
i did but adding stage-0 broke my build
couldnt find stage-0
Ginger
@GingerChew
Aug 24 2017 02:42
@sjames1958gm gotcha, so I'll avoid doing that
@sjames1958gm thanks m8
CamperBot
@camperbot
Aug 24 2017 02:42
gingerchew sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8374 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 24 2017 02:43
@Pagnito npm install it as a dev dependency babel-preset-stage-0
@GingerChew :+1:
juni
@junipberry
Aug 24 2017 02:43

I’m having trouble passing this line:

function getLastElement(array) {
  if (array.length === 0) {
    return undefined;
  } else {
  return array[-1];
}
}

and not seeing what is wrong w it..

Stephen James
@sjames1958gm
Aug 24 2017 02:44
@junipberry array.length - 1 is the index of the last entry not -1
Pagnito
@Pagnito
Aug 24 2017 02:44
did everything to the t, still doesnt work
the weird thing is that if i define a handler in my header child, it works, but in the recipeList it doesnt
juni
@junipberry
Aug 24 2017 02:44
ahhhh
right
Pagnito
@Pagnito
Aug 24 2017 02:45
how the fcccck
juni
@junipberry
Aug 24 2017 02:45
ty again @sjames1958gm
Stephen James
@sjames1958gm
Aug 24 2017 02:45
@junipberry you're welcome
Greg Duncan
@GregatGit
Aug 24 2017 02:46
@Pagnito my advice would be - build it using create-react-app
then once you have it working build your own boiler plate - but webpack can be tricky and you should be focused on creating and executing simple functions rather than wondering if all is compling correctly
Pagnito
@Pagnito
Aug 24 2017 02:46
@GregatGit how can i install create-react-app locally?
Stephen James
@sjames1958gm
Aug 24 2017 02:47
npm install -g create-react-app
Greg Duncan
@GregatGit
Aug 24 2017 02:47
@Pagnito very simple
Pagnito
@Pagnito
Aug 24 2017 02:47
@sjames1958gm thats globally tho
juni
@junipberry
Aug 24 2017 02:47
oddly, this is not passing :
function getLastElement(array) {
  if (array.length === 0) {
    return undefined;
  } else {
  return array.length - 1;
}
}
Pagnito
@Pagnito
Aug 24 2017 02:47
@GregatGit how tho lol >.<
Stephen James
@sjames1958gm
Aug 24 2017 02:48
@junipberry You still need to use the array as in array[array.length - 1]
Greg Duncan
@GregatGit
Aug 24 2017 02:48
@Pagnito
npm install -g create-react-app

create-react-app my-app
cd my-app/
npm start
juni
@junipberry
Aug 24 2017 02:48
got it ty @GregatGit
CamperBot
@camperbot
Aug 24 2017 02:48
junipberry sends brownie points to @gregatgit :sparkles: :thumbsup: :sparkles:
:cookie: 883 | @gregatgit |http://www.freecodecamp.com/gregatgit
Stephen James
@sjames1958gm
Aug 24 2017 02:48
Its meant to be installed globally
Greg Duncan
@GregatGit
Aug 24 2017 02:48
@Pagnito just don't call it 'my-app'
Pagnito
@Pagnito
Aug 24 2017 02:49
so i install it only once? and then jsut create-react-app whenever i want to starta project?
Greg Duncan
@GregatGit
Aug 24 2017 02:49
@Pagnito yes
Pagnito
@Pagnito
Aug 24 2017 02:49
hmm pretty sweet
Greg Duncan
@GregatGit
Aug 24 2017 02:49
npm install -g create-react-app this line once
@Pagnito I spent hours trying fix up webpack configs when I could of been working on react
Pagnito
@Pagnito
Aug 24 2017 02:51
hm i guess u right
Greg Duncan
@GregatGit
Aug 24 2017 02:51
@Pagnito CRA is improving all the time - the team who work on it want it to be the goto for your react apps
Pagnito
@Pagnito
Aug 24 2017 02:52
cra?
ooh
nvm lol create react app
i guess it makes sense, i can always just add on whatever other modules nad plugins i want
Greg Duncan
@GregatGit
Aug 24 2017 02:53
yep
John
@AnonymousLords
Aug 24 2017 02:54
still dont know why broken2 = broken2.push(arr[1].split("")); is undefined

function mutation(arr) {
  var broken2 = [];
  var count = 0;


  for (var i = 0; arr[0].length > i, i++;) {
     broken2 = broken2.push(arr[1].split(""));

    while (arr[0].indexOff(broken[i]) !== -1) {
      count + arr[0].length;

      if (count == arr[0].length * arr[1].length) {
        return true;
      }
      else false;
    }
  }
}

mutation(["floor", "for"]);
Pagnito
@Pagnito
Aug 24 2017 02:54
@GregatGit whats manifest.json do
Greg Duncan
@GregatGit
Aug 24 2017 02:55
@Pagnito dont know
John
@AnonymousLords
Aug 24 2017 02:55
@ smart people :point_up: August 23, 2017 10:54 PM
Greg Duncan
@GregatGit
Aug 24 2017 02:56
@AnonymousLords broken2.push(arr[1].split("")) is enough
John
@AnonymousLords
Aug 24 2017 02:57
console.log(broken2.push(arr[1].split(""))); is undefinded
Greg Duncan
@GregatGit
Aug 24 2017 02:58
@AnonymousLords what are you trying to do in that line
John
@AnonymousLords
Aug 24 2017 02:59
just add the split form of the 2nd element (for) tobroken2
do i need to split then push?
Greg Duncan
@GregatGit
Aug 24 2017 03:00
@AnonymousLords in this particular case what did you expect broken2 to equal (this first time it hits)
John
@AnonymousLords
Aug 24 2017 03:01
Oh wait does it need to be outside the for loop?
Greg Duncan
@GregatGit
Aug 24 2017 03:03
@AnonymousLords your code is confusing and wrong - so it's hard to tell what you wanted - so if it did work what would broken2's value be?
John
@AnonymousLords
Aug 24 2017 03:03
Just [ 'f', 'o', 'r' ]
But if i push it i get one
Pagnito
@Pagnito
Aug 24 2017 03:04
@GregatGit hey do u use a mac?
Greg Duncan
@GregatGit
Aug 24 2017 03:05
@AnonymousLords to do that
function mutation(arr) {
  var broken2 = arr[1].split('');
   ...
@Pagnito no - are you having a problem with CRA
John
@AnonymousLords
Aug 24 2017 03:06
oh
Pagnito
@Pagnito
Aug 24 2017 03:06
@GregatGit not really, just when i installed it, my md_workers in activity monitor went bananas and took up all my cpu for a while
John
@AnonymousLords
Aug 24 2017 03:06
Okay i added that to my code
Greg Duncan
@GregatGit
Aug 24 2017 03:07
@AnonymousLords move broken2 out of the loop
John
@AnonymousLords
Aug 24 2017 03:07

function mutation(arr) {
  var count = 0;
  broken2 = arr[1].split("");

  for (var i = 0; arr[0].length > i, i++;) {

    while (arr[0].indexOff(broken[i]) !== -1) {
      count + arr[0].length;

      if (count == arr[0].length * arr[1].length) {
        return true;
      }
      else false;
    }
  }
}

mutation(["floor", "for"]);
I just dsicovered some plot holes in my code
Greg Duncan
@GregatGit
Aug 24 2017 03:12
@AnonymousLords i used toLowerCase() in my code
John
@AnonymousLords
Aug 24 2017 03:12
ohh forgot
Ginger
@GingerChew
Aug 24 2017 03:13
I can't seem to figure out how these closures work, how do I call a function that uses the second argument here?
function addTogether() {
  var arg = [].slice.call(arguments), argSum = arg[0];
  function sumTwoAnd(arg) {
    if (typeof arg[0]  == 'number') {
      arg += arguments[1];
    } else if (typeof arg[0] == 'number' && arg.length <2){
      return undefined;
    }
    return arg0;
  } 
  return arg;
}


addTogether(2,3);
if it was addTogether(2)(3);
John
@AnonymousLords
Aug 24 2017 03:14
Wait i think i fixed most of my errors
Greg Duncan
@GregatGit
Aug 24 2017 03:15
@GingerChew What is the challenge called?
Ginger
@GingerChew
Aug 24 2017 03:15
Arguments Optional
Greg Duncan
@GregatGit
Aug 24 2017 03:18
@AnonymousLords you can only make the words in the arr lowercase - you just can't do that to the entire array
John
@AnonymousLords
Aug 24 2017 03:19
so would i add it in my loop with i?
How would i lowercaseevery word
nvm i fixed it
Greg Duncan
@GregatGit
Aug 24 2017 03:21
@GingerChew I found this one pretty tough - but for addTogether(2)([3]) case you have to return a function
@AnonymousLords arr[0].toLowerCase()
John
@AnonymousLords
Aug 24 2017 03:22
It need to lowercase both words
I just did arr[i].toLowerCase()
in my loop
Fixed a typo, it was listing broken2 as broken
my new code

function mutation(arr) {

  for (var i = 0; arr[0].length > i, i++;) {
    arr = arr[i].toLowerCase();
    broken2 = arr[1].split("");
    return arr[0].indexOff(broken2[i]) !== -1;
  }
}

mutation(["floor", "foor"]);
Its returning something undefined
Greg Duncan
@GregatGit
Aug 24 2017 03:29
@AnonymousLords before you get in the loop create make sure you have two varibles with a lower case of each word
John
@AnonymousLords
Aug 24 2017 03:31
okay
arr = arr[0].toLowerCase();?
Gersho
@Gersho
Aug 24 2017 03:33
arr[0] = arr[0].toLowerCase();
arr[1] = arr[1].toLowerCase();
?
John
@AnonymousLords
Aug 24 2017 03:34
function mutation(arr) {
 arr[0] = arr[0].toLowerCase();
 arr[1] = arr[1].toLowerCase();

  for (var i = 0; arr[0].length > i; i++) {
    var broken2 = arr[1].split("");
    return arr[0].indexOf(broken2[i]) !== -1;
  }
}

mutation(["floor", "foor"]);
Gersho
@Gersho
Aug 24 2017 03:35
you're not declaring broken2
John
@AnonymousLords
Aug 24 2017 03:35
var
Gersho
@Gersho
Aug 24 2017 03:36
it will return at the first itteration
John
@AnonymousLords
Aug 24 2017 03:37
Its currently just returning undefined
Gersho
@Gersho
Aug 24 2017 03:37
you could try using break/continue, or have a boolean switch outside the loop
indexOff ? indexOf ;)
John
@AnonymousLords
Aug 24 2017 03:38
Still undefined
Gersho
@Gersho
Aug 24 2017 03:41
from my understanding it should return true in that case, try putting some console.log checking values and type or arr[0] arr[1] and broken2
should be 2 strings and an array, but if it's returing undefined we're obviously missing something
oh
John
@AnonymousLords
Aug 24 2017 03:42
:D
Gersho
@Gersho
Aug 24 2017 03:42
(var i = 0; arr[0].length > i, i++;)
should be a ; after the > i , and no ; after i++
also i'd put i<arr[0].length, it's the same but i prefer to put the i first for readability
John
@AnonymousLords
Aug 24 2017 03:44
function mutation(arr) {
 arr[0] = arr[0].toLowerCase();
 arr[1] = arr[1].toLowerCase();

  for (var i = 0; i < arr[0].length; i++) {
    var broken2 = arr[1].split("");
    console.log(arr[0].indexOf(broken2[i]) !== -1);
  }
  return 
}

mutation(["floor", "foor"]);
true
true
true
true
false
=> undefined
Gersho
@Gersho
Aug 24 2017 03:45
wonder why the 5th returned false, but i'll still consider that progress
the undefined is normal since return was used alone
John
@AnonymousLords
Aug 24 2017 03:46
?
Gersho
@Gersho
Aug 24 2017 03:46
oh wait i hadn't noticed both word weren't the same lol
John
@AnonymousLords
Aug 24 2017 03:47
How would i do it so it returned true or false, even then its just comparing the words and not checking letters
WAIT
Gersho
@Gersho
Aug 24 2017 03:48
oh, shouldn't it be arr[1].length instead or arr[0].length ? since Return true if the string in the first element of the array contains all of the letters of the string in the--> second<-- element of the array.
John
@AnonymousLords
Aug 24 2017 03:48
put your tin foil hats on
should i compare the first element to the second element ?
:shipit:
Gersho
@Gersho
Aug 24 2017 03:49
well here you are making individual checks, but you can't return it right away, because you need to do ALL the test, and return true only if all are true
John
@AnonymousLords
Aug 24 2017 03:50
Wait should my code remove any letters that arent the same, and comapre the two words at the end?
nvm
Gersho
@Gersho
Aug 24 2017 03:50
from the challenge tests:
mutation(["floor", "for"]) should return true.
since it's true, it means it didn't check for the L in floor
John
@AnonymousLords
Aug 24 2017 03:50
humm
Okay
Gersho
@Gersho
Aug 24 2017 03:50
no for exemple for floor/for, you need to check if the floor word has the letter f / o / r of the for word
(am i making sense ?)
John
@AnonymousLords
Aug 24 2017 03:51
Yes
Gersho
@Gersho
Aug 24 2017 03:51
check the expected output on the bottom left, helps to understand what they want
John
@AnonymousLords
Aug 24 2017 03:51
ik
But how do i check without accidentally returning false because of that L
Gersho
@Gersho
Aug 24 2017 03:52
your code is already checking properly that part as far as i understand it
John
@AnonymousLords
Aug 24 2017 03:53
It returns false because of that l
Gersho
@Gersho
Aug 24 2017 03:53
arr[0].indexOf(broken2[i]) checks if arr0 has broken2 letters, so i won't test for l
no
John
@AnonymousLords
Aug 24 2017 03:53
Oh
Gersho
@Gersho
Aug 24 2017 03:53
it returns false because it tests broken2[4]
because i < arr[0].length
John
@AnonymousLords
Aug 24 2017 03:53
Oh
Gersho
@Gersho
Aug 24 2017 03:53
should be arr[1].length
John
@AnonymousLords
Aug 24 2017 03:54
Okay now i just need a bollean switch
Gersho
@Gersho
Aug 24 2017 03:54
you test f, then o, then r, then ??!!??
John
@AnonymousLords
Aug 24 2017 03:54
/boolean
Oh okay
Gersho
@Gersho
Aug 24 2017 03:55
the boolean is simple, before the loop set the variable as true, in the loop, if you can't find the letter you check, return false, else continue, if you do all loops and it's still true, then return true
John
@AnonymousLords
Aug 24 2017 03:57
so a if statement
@Gersho
Gersho
@Gersho
Aug 24 2017 03:57
yep
John
@AnonymousLords
Aug 24 2017 03:58
if i is false?
Gersho
@Gersho
Aug 24 2017 03:59
@AnonymousLords if (arr[0].indexOf(broken2[i]) !== -1)
or === depending on how you want to write it
John
@AnonymousLords
Aug 24 2017 04:00
so far my code

function mutation(arr) {
 arr[0] = arr[0].toLowerCase();
 arr[1] = arr[1].toLowerCase();

  var loop = true; 

  for (var i = 0; i < arr[0].length; i++) {
    var broken2 = arr[1].split("");
    if (arr[0].indexOf(broken2[i]) !== -1);

  }

}

mutation(["floor", "hoor"]);
Gersho
@Gersho
Aug 24 2017 04:01
{continue;}else {return false;}
and return true; after the loop

function mutation(arr) {
 arr[0] = arr[0].toLowerCase();
 arr[1] = arr[1].toLowerCase();

  var loop = true; 

  for (var i = 0; i < arr[0].length; i++) {
    var broken2 = arr[1].split("");
    if (arr[0].indexOf(broken2[i]) !== -1){continue;}else {return false;}

  }
  return true;
}

mutation(["floor", "hoor"]);
or smth like that, should be close to it
John
@AnonymousLords
Aug 24 2017 04:03
How would i make it so it continues
Gersho
@Gersho
Aug 24 2017 04:04
continue;
John
@AnonymousLords
Aug 24 2017 04:04
thats a keyword?
Gersho
@Gersho
Aug 24 2017 04:04
yes
there's break too, you should check them they help when manipulating for loops
John
@AnonymousLords
Aug 24 2017 04:05
if (arr[0].indexOf(broken2[i]) !== -1 continue ? false);
Gersho
@Gersho
Aug 24 2017 04:05

but you could also

if (arr[0].indexOf(broken2[i]) === -1){return false;}

you wouldn't need the continue or the else in that case

@AnonymousLords are you mixing ? with if's ?
John
@AnonymousLords
Aug 24 2017 04:06
would it work?
Gersho
@Gersho
Aug 24 2017 04:06
don't think so
John
@AnonymousLords
Aug 24 2017 04:06
oh
Gersho
@Gersho
Aug 24 2017 04:07
by now you should have everything to complete it :)
John
@AnonymousLords
Aug 24 2017 04:08
if (arr[0].indexOf(broken2[i]) === -1{return false;});
Gersho
@Gersho
Aug 24 2017 04:09
i think you have a ) too much at the end, but yeah that's it
John
@AnonymousLords
Aug 24 2017 04:10
unknown: Unexpected token (10:42)
   8 |   for (var i = 0; i < arr[0].length; i++) {
   9 |     var broken2 = arr[1].split("");
> 10 |     if (arr[0].indexOf(broken2[i]) === -1 {return false;})) {
     |                                           ^
  11 |         return true;
  12 |     }
  13 |
Gersho
@Gersho
Aug 24 2017 04:12
by the way you don't need to have var broken2 = arr[1].split(""); inside the loop, you can put it before, also i think your return true is still inside the loop, you have extra )) at the end of line 10, what is the block containing return true; ?
John
@AnonymousLords
Aug 24 2017 04:13
function mutation(arr) {
 arr[0] = arr[0].toLowerCase();
 arr[1] = arr[1].toLowerCase();

  var loop = true; 

  for (var i = 0; i < arr[0].length; i++) {
    var broken2 = arr[1].split("");
    if (arr[0].indexOf(broken2[i]) === -1) {
        return false;
    }
    return true;

  }

}


mutation(["floor", "toor"]);
It works all but one
Moisés Man
@moigithub
Aug 24 2017 04:15
return exit the function immediatelly @AnonymousLords
John
@AnonymousLords
Aug 24 2017 04:15
?
Gersho
@Gersho
Aug 24 2017 04:17
return true; put it outside the for loop
John
@AnonymousLords
Aug 24 2017 04:19

function mutation(arr) {
 arr[0] = arr[0].toLowerCase();
 arr[1] = arr[1].toLowerCase();

  var loop = true; 

  for (var i = 0; i < arr[0].length; i++) {
    var broken2 = arr[1].split("");
    if (arr[0].indexOf(broken2[i]) === -1) {
        return false;
    }

  }
return true;
}


mutation(["hello", "hey"]);
Now 3 things are wrong instead of 1 ;-;
Moisés Man
@moigithub
Aug 24 2017 04:19
u using wrong index on broken2
hello contains 5 characters
hey only 3
soo if u do "hey"[4] <-- hey dont have 4th char
Gersho
@Gersho
Aug 24 2017 04:20
i < arr[0].length should be arr[1].length
John
@AnonymousLords
Aug 24 2017 04:21
I got it :D thanks

function mutation(arr) {
 arr[0] = arr[0].toLowerCase();
 arr[1] = arr[1].toLowerCase();

  var loop = true; 

  for (var i = 0; i < arr[1].length; i++) {
    var broken2 = arr[1].split("");
    if (arr[0].indexOf(broken2[i]) === -1) {
        return false;
    }

  }
return true;
}


mutation(["hello", "hey"]);
@AnonymousLords @Gersho @moigithub @GregatGit thanks
CamperBot
@camperbot
Aug 24 2017 04:21
anonymouslords sends brownie points to @gersho and @moigithub and @gregatgit :sparkles: :thumbsup: :sparkles:
:cookie: 353 | @gersho |http://www.freecodecamp.com/gersho
:star2: 3604 | @moigithub |http://www.freecodecamp.com/moigithub
api offline
Greg Duncan
@GregatGit
Aug 24 2017 04:22
@AnonymousLords Well done! :fire:
John
@AnonymousLords
Aug 24 2017 04:23
thanks @GregatGit
CamperBot
@camperbot
Aug 24 2017 04:23
anonymouslords sends brownie points to @gregatgit :sparkles: :thumbsup: :sparkles:
:cookie: 884 | @gregatgit |http://www.freecodecamp.com/gregatgit
Gersho
@Gersho
Aug 24 2017 04:23
:thumbsup:
John
@AnonymousLords
Aug 24 2017 04:24
:D thanks guys so much. I feel like im getting better and better at these
Imagine when they create ai
Gersho
@Gersho
Aug 24 2017 04:24
i would say that's the point
can't wait to meet our robot overlord
John
@AnonymousLords
Aug 24 2017 04:25
what is camperbot was ai
It it learned to code based off of us
I dont know if such ai is possible
Giving it the ability to learn like that
and think
and logic
Gersho
@Gersho
Aug 24 2017 04:28
and it'll learn to hate us reading youtube comments and twitter
John
@AnonymousLords
Aug 24 2017 04:46
o
murp9702
@murp9702
Aug 24 2017 05:33
Anyone have a minute to help me figure out an API from NOAA? I cannot get it to select the dataset I want.
prakash chandra yadav
@prakashyadav008
Aug 24 2017 05:34
hey everyone a little help her
here*
how do i get the search bar to expand to the left
LiciniusRex
@hashtagyolo1
Aug 24 2017 06:58
been stuck on this for a bit now. I need to access the info in the variable outside the function. I cannot seem to work out how to do that though. Any help would be greatly appreciated.
function hereIAm() {
  navigator.geolocation.getCurrentPosition(function(position) {
    var hereItIs = position.coords.latitude + "," + position.coords.longitude;
  });
}

console.log(
  "https://api.darksky.net/forecast/2ab2f9b932f8da4e2c0de813592b9d1f/" +
    hereIAm +
    "?exclude=minutely,hourly,daily,alerts,flags?units=auto"
);
Markus Kiili
@Masd925
Aug 24 2017 07:01
@hashtagyolo1 hereIAm is a function. hereIAm() would execute the function and evaluate to the function return value.
Remember that geolocation callback function is executed at some time later when the location response comes.
Claudio Restifo
@Marmiz
Aug 24 2017 07:40
Someone here willing to give me a hand about Higher Order Component :)
LiciniusRex
@hashtagyolo1
Aug 24 2017 08:37
Thsnks @Masd925 , that is looking a lot better. However It's returning undefined rather than variable
function hereIAm() {
  navigator.geolocation.getCurrentPosition(function(position) {
  var hereItIs = position.coords.latitude + "," + position.coords.longitude;
  return hereItIs;
  });
}

console.log(
  "https://api.darksky.net/forecast/2ab2f9b932f8da4e2c0de813592b9d1f/" +
    hereIAm() +
    "?exclude=minutely,hourly,daily,alerts,flags?units=auto"
);
Markus Kiili
@Masd925
Aug 24 2017 08:38
@hashtagyolo1 That return is from the geolocation callback function, and not the hereIAM function.
Gulsvi
@gulsvi
Aug 24 2017 08:39
And, you should return the variable rockYouLikeAHurricane
Markus Kiili
@Masd925
Aug 24 2017 08:39
@hashtagyolo1 In any way, that code structure is not going to work.
You need to use the response stored in position inside the geolocation callback function.
LiciniusRex
@hashtagyolo1
Aug 24 2017 08:40
@Masd925 . OK. Back to the drawing board :)
LiciniusRex
@hashtagyolo1
Aug 24 2017 08:49
Right, off for the weekend. Thanks to everyone who's been helping. Laters
Slitherings
@Slitherings
Aug 24 2017 09:28
wanted to see if anyone knew how i could convert a string of words into a array
Markus Kiili
@Masd925
Aug 24 2017 09:31
@Slitherings str.split(" ");
Anabel
@AnabelSalomone
Aug 24 2017 09:47
I need help to understand this:
for (var i = 0; i < tab.length; i++) {
   obj[tab[i]] = (obj[tab[i]] || 0) + 1;  
}
Sometimes obj[tab[i]] is an obj key, sometimes it's a number. WHY?! haha it drives me crazy
Full code:
let tab = ["orange", "orange", "kiwi", "ananas", "kiwi", "ananas", "banane", "prune", "orange", "orange", "orange", "orange", "orange", "orange", "kiwi", "kiwi","prune", "banane", "pamplemousse", "ananas"];


var obj = { };


for (var i = 0; i < tab.length; i++) {
   obj[tab[i]] = (obj[tab[i]] || 0) + 1;  
}
Returns: [object Object] { ananas: 3, banane: 2, kiwi: 4, orange: 8, pamplemousse: 1, prune: 2 }
Stephen James
@sjames1958gm
Aug 24 2017 09:51
@AnabelSalomone The idea is that if obj[tab[i]] is not set (undefined) then use 0 else use the value from the property
So, when you hit a string for the first time you set the value to 0 + 1 otherwise you set the value to obj[tab[i]] + 1
@AnabelSalomone undefined || 0 => gives 0 while number || 0 => gives number (assuming number not zer0)
Anabel
@AnabelSalomone
Aug 24 2017 09:53
Yes, I see. I just wonder why obj[tab[i]] can be "orange" and then a number. I don't know if my question is clear '^^

obj[tab[i]] = (obj[tab[i]] || 0) + 1;

is for example

orange = 0

heroiczero
@heroiczero
Aug 24 2017 09:53
@AnabelSalomone its is just adding 1 if it is "orange" in the list or
Anabel
@AnabelSalomone
Aug 24 2017 09:53
but they both use obj[tab[i]]
Stephen James
@sjames1958gm
Aug 24 2017 09:53
@AnabelSalomone obj[tab[i]] is never "orange"
Anabel
@AnabelSalomone
Aug 24 2017 09:54
aaah ok I see now! I think I understand
Stephen James
@sjames1958gm
Aug 24 2017 09:54
obj[tab[i]] is undefined then 1
Anabel
@AnabelSalomone
Aug 24 2017 09:54
and when does it set a new key in the object?
Stephen James
@sjames1958gm
Aug 24 2017 09:55
tab[i] is "orange" so you have obj["orange"] which is undefined at first when you have obj["orange"] = 0 + 1
When you set that then you have the key set in obj
Anabel
@AnabelSalomone
Aug 24 2017 09:56
It's still bit tricky for a newbee like me '^^ Thank you @sjames1958gm for your help! :)
CamperBot
@camperbot
Aug 24 2017 09:56
anabelsalomone sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8375 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 24 2017 09:59
@AnabelSalomone That is why sometimes "clever" code is not a "good" as explicit code.
Perhaps this would be more readable for newer developers.
obj[tab[i]] = obj[tab[i]] ? obj[tab[i]] + 1 : 1;
But this is probably clearer
if (obj[tab[i]]) 
   obj[tab[i]] ++
else
  obj[tab[i]] = 1;
Markus Kiili
@Masd925
Aug 24 2017 10:17
@sjames1958gm To me, testing for truthiness when you are really testing for something else (like property key existence here), seems misleading. Understanding the code then requires looking at the data and reasoning what the test is really about.
Just conforming your clever code statement.
Pethaf
@Pethaf
Aug 24 2017 11:10
People, I need some help.
https://codepen.io/pethaf/pen/wqxMro this works in firefox, but in chrome the globe is just a square. What gives?
Stephen James
@sjames1958gm
Aug 24 2017 11:24
@Masd925 :+1:
@Pethaf I am on chrome and the globe is a globe
Blauelf
@Blauelf
Aug 24 2017 11:29
@sjames1958gm Not for me on Windows NT 6.1. Arial just doesn't have the symbol on my PC, neither does the font used for displaying the source code. I really wonder how Firefox adds those.
Stephen James
@sjames1958gm
Aug 24 2017 11:30
I am on Ubuntu chrome version 57
Pethaf
@Pethaf
Aug 24 2017 11:30
I guess I will have to add oswald or roboto.
Blauelf
@Blauelf
Aug 24 2017 11:30
Oh, then not using the same font I guess.
Pethaf
@Pethaf
Aug 24 2017 11:33
I growing tired of this.
I am going to go the fontawesome route.
Stephen James
@sjames1958gm
Aug 24 2017 11:46
@Pethaf :(
Jen
@jenniredfield
Aug 24 2017 13:54
hi guys, IM doing the wikipedia viwer challenge and all my data is back on a object, but how can I access all the objects inside an object? bracket notation and dot notation dont work :/
ok, no one here lol
Keith
@7KAG7
Aug 24 2017 13:58
$(document).ready(function(){
//fcc stream info and status api call
  var url= "https://wind-bow.gomix.me/twitch-api/streams/:freecodecamp";
  $.getJSON(url,function(data1){
    if(data1.stream===null){
      $("#fccStatus").html("is currently offline!")
    }
    else{
    $("#fccStatus").html("is currently online!") 
    }
  });
});
any idea what this wont prompt the online/offline status?
<div class = "container">
    <div id= "header" class= "text-center">
   <h1>Twitch JSON API </h1>
        <a href= "https://www.twitch.tv/freecodecamp" target= "blank"> <h2> freeCodeCamp </h2>

         <h3 id= "fccStatus"></h3> 
</a>
  </div>
korzo
@korzo
Aug 24 2017 14:06
@dudeguykid I think your url si wrong
Keith
@7KAG7
Aug 24 2017 14:06
thats straight from the challenge page on FCC
Pagnito
@Pagnito
Aug 24 2017 14:07
@GregatGit hey
Keith
@7KAG7
Aug 24 2017 14:07
althought yes i agree, it doesnt currently get me to any active site
Stephen James
@sjames1958gm
Aug 24 2017 14:10
https://wind-bow.glitch.me/twitch-api/users/freecodecamp
Don't use : that is only trying to indicate the route to use
korzo
@korzo
Aug 24 2017 14:10
@dudeguykid correct url is https://wind-bow.glitch.me/twitch-api/streams/freecodecamp
Keith
@7KAG7
Aug 24 2017 14:10

facepalm

i only did that b/c it was in the example from FCC
Stephen James
@sjames1958gm
Aug 24 2017 14:11
@jenniredfield pen link?
ok it still wont show the status though
Stephen James
@sjames1958gm
Aug 24 2017 14:11
@dudeguykid /users/:user this is how you specify a variable in a route :user is replaced by the username
Keith
@7KAG7
Aug 24 2017 14:12
ah
if you look on the console you will see that I get back.. I cant access any of it though...
Jefferson
@jeffersonnnn
Aug 24 2017 14:13

Hi guys, i am at the Seek and destroy challenge, and i need a bit of input. Here is my code ```js
function destroyer(arr) {
var argsToArray = arr.prototype.slice.call(destroyer);
return argsToArray;

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
```

the syntax (for mamo seems a lot off-kilter though.

Stephen James
@sjames1958gm
Aug 24 2017 14:14
@jenniredfield Try this
    for (key in myObj) {
      console.log(myObj[key].title);
    }
@jenniredfield The keys for the pages are long numbers, so use this for loop to extract them in a loop
@jeffersonnnn argsToArray this will be [[1, 2, 3, 1, 2, 3], 2, 3] and array of the values passed to the function.
Blauelf
@Blauelf
Aug 24 2017 14:20
@jeffersonnnn Either arr.slice.call or Array.prototype.slice.call (as arr inherits from Array.prototype, where slice is located, those are the same).
Jen
@jenniredfield
Aug 24 2017 14:23
@sjames1958gm ahh the property names are the ids right
@sjames1958gm brownie to yas
@sjames1958gm thanks
CamperBot
@camperbot
Aug 24 2017 14:24
jenniredfield sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8378 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Jefferson
@jeffersonnnn
Aug 24 2017 14:26
But i used the later array.prototype.slice.call and i am not getting results.
Keith
@7KAG7
Aug 24 2017 14:27
@sjames1958gm @korzo thanks for the help
CamperBot
@camperbot
Aug 24 2017 14:27
dudeguykid sends brownie points to @sjames1958gm and @korzo :sparkles: :thumbsup: :sparkles:
:cookie: 407 | @korzo |http://www.freecodecamp.com/korzo
:star2: 8379 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Aug 24 2017 14:29
@jeffersonnnn You have to use Array.prototype or arr.prototype
because array doesn't exist in the function
Stephen James
@sjames1958gm
Aug 24 2017 14:35
@jenniredfield :+1:
@dudeguykid YW
Jefferson
@jeffersonnnn
Aug 24 2017 14:43
i just slid the results into pythontutor and saw same results
function destroyer(array) {
  var argsToArray = array.prototype.slice.call(destroyer);
  return argsToArray;

}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Stephen James
@sjames1958gm
Aug 24 2017 14:52
@jeffersonnnn hmm
Pagnito
@Pagnito
Aug 24 2017 14:54
@Marmiz turns ou it wasnt my build lol
Stephen James
@sjames1958gm
Aug 24 2017 14:54
@jeffersonnnn Ah, you don't need the prototype when using an actual array.
@jeffersonnnn But you need to pass arguments to call not the function name
Pagnito
@Pagnito
Aug 24 2017 14:54
@Marmiz i had forgot to use position relative on one of my z-indexed elements so thats why it seemed like jquery and events didnt work
O.o lol a classic :worried:
Stephen James
@sjames1958gm
Aug 24 2017 14:55
@Pagnito So your clicks weren't actually getting to the element with the click handler? It was covered by another element
Pagnito
@Pagnito
Aug 24 2017 14:55
@sjames1958gm yea by the parent element O.o
Stephen James
@sjames1958gm
Aug 24 2017 14:55
@Pagnito Dang!
Pagnito
@Pagnito
Aug 24 2017 14:55
lol right
i used the z-indexes with negative values it fucked it up
and didnt use position relative on the recipeList
feels so good to finally be able to move on with the project
Jefferson
@jeffersonnnn
Aug 24 2017 15:00
@sjames1958gm alrighty then. Lemme try again.
Stephen James
@sjames1958gm
Aug 24 2017 15:07
@jeffersonnnn :+1:
Jen
@jenniredfield
Aug 24 2017 15:10
hi Stephen are you still there
Stephen James
@sjames1958gm
Aug 24 2017 15:10
@jenniredfield yes
Jen
@jenniredfield
Aug 24 2017 15:11
how you would access each title individually ? console.log(myObj[key].title[0] wouldnt work
i need to loop through each and print each and thats my problem now hehe
Stephen James
@sjames1958gm
Aug 24 2017 15:14
myObj[key].title this is the tile fro the page referenced by key
You loop through the pages with
for (key in myObj) {
then myObj[key] is the page, each with an individual title
Jen
@jenniredfield
Aug 24 2017 15:16
but when I print it only shows the last one cos it overwrites it
Stephen James
@sjames1958gm
Aug 24 2017 15:19
@jenniredfield
       var newContent = "";
       for (key in myObj) {
         newContent += '<p>' + myObj[key].title + '</p>';
      }
      document.querySelector('.content').innerHTML = newContent;
Marc
@MWBauer
Aug 24 2017 15:22
anyone wanna' talk about constructors for a second?
Jen
@jenniredfield
Aug 24 2017 15:23
@sjames1958gm what , just that??
Stephen James
@sjames1958gm
Aug 24 2017 15:23
@jenniredfield Yes, because the for loop is already looping over the pages, you don't need another loop.
Jen
@jenniredfield
Aug 24 2017 15:24
@sjames1958gm I was creating another one -_- loads and loads of lines of code haha
@sjames1958gm thannkss
Stephen James
@sjames1958gm
Aug 24 2017 15:26
@jenniredfield Sure
Marc
@MWBauer
Aug 24 2017 15:27
When using constructors, one of the lessons is Make Instances. var Car = * creates an object that you can define now and call later, right?
by using new Car() I can update it and that changes the Car or makes a new instance of Car()?
Stephen James
@sjames1958gm
Aug 24 2017 15:36
@MWBauer var Car = function() { this function is a constructor function.
it really doesn't create an object (other than in js functions are objects).
It creates a template for creating new objects which are created by new Car();
Makes a new instance
Marc
@MWBauer
Aug 24 2017 15:39
Ok. Thanks.
Klaus Mana
@KlausMana
Aug 24 2017 18:06
hello there
Matej Bošnjak
@mbosnjak01
Aug 24 2017 19:14
Hi. Quick question. What would be better to use when checking if a string inside an JS objects property is http or https (url) ... .includes() or .match() ?
maybe thire option that's better than both of those? ... just looking for best practices
third*
Mark
@vinarius
Aug 24 2017 19:17
can you use an if statement? if(myObj.myProp === "https"){ //do stuff... } else if(myObj.myProp === "http"){ //do other stuff... } else { //error }
Matej Bošnjak
@mbosnjak01
Aug 24 2017 19:17
i don't need else for http or https
just http || https
and yes, if statement is way to go
Mohammed Boudad
@matrixersp
Aug 24 2017 19:50
I get an error when I try to compare the length of the variable temp : "Cannot read property 'length' of undefined", temp is also an array, I don't understand why!
var arr = [[3, [[4]]], 5];
temp = arr[0];
while(temp.length > 0) {}
Matej Bošnjak
@mbosnjak01
Aug 24 2017 19:51
temp is not an array
in temp you call first key from an array
if you do console.log on temp it should display 3 as a string, if I am not mistaken
Mohammed Boudad
@matrixersp
Aug 24 2017 19:52
@mbosnjak01 Yes it displays 2
But how can I copy it as an array?
Diego Mayer
@Chrono79
Aug 24 2017 19:55
var arr = [[3, [[4]]], 5];
var temp = arr[0];
console.log(temp); // [ 3, [ [ 4 ] ] ]
console.log(temp.length); // 2
Matej Bošnjak
@mbosnjak01
Aug 24 2017 19:56
oh it is array, sorry...missed that double [] there
Diego Mayer
@Chrono79
Aug 24 2017 19:56
temp is an array, what are you doing with it after that? @Tekkie7
Matej Bošnjak
@mbosnjak01
Aug 24 2017 19:57
yeah length works.
Mohammed Boudad
@matrixersp
Aug 24 2017 19:57
@Chrono79 Why it gives me that error then when I compare its length in a while loop?
Diego Mayer
@Chrono79
Aug 24 2017 19:58
@Tekkie7 that loop is an infinite one, maybe you're changing the value of temp to something that hasn't length property somewhere
Mohammed Boudad
@matrixersp
Aug 24 2017 19:58
@Chrono79 I know, it was just an expample
Diego Mayer
@Chrono79
Aug 24 2017 19:59
var arr = [[3, [[4]]], 5];
var temp = arr[0];
while(temp.length > 0) {
  temp.pop();
  console.log(temp.length);
}
This works and prints 1 and 0 before ending the loop
Matej Bošnjak
@mbosnjak01
Aug 24 2017 19:59
what's .pop()?
Diego Mayer
@Chrono79
Aug 24 2017 19:59
@Tekkie7 if temp is not an array (or a string) you'll get that error, for instance if arr is [3, [4, 5]]
Mohammed Boudad
@matrixersp
Aug 24 2017 20:08
Capture.PNG
Diego Mayer
@Chrono79
Aug 24 2017 20:12
@Tekkie7 do a console.log inside the loops to see when it's failing
Mohammed Boudad
@matrixersp
Aug 24 2017 20:13
@Chrono79 it displays 2
Diego Mayer
@Chrono79
Aug 24 2017 20:13
copy and paste the code here formatted
```js
your code
Mohammed Boudad
@matrixersp
Aug 24 2017 20:14
Well this is not working, I'm trying to figure out how to compare that array without getting an error
function steamrollArray(arr) {
  // I'm a steamroller, baby
    var arr2 =[];
    var temp = [];
    var count = 0;
    for(var i = 0; i < arr.length; i++) {
        temp = arr[0];
        console.log(temp.length);
        while(temp.length > 0) {
            console.log(temp.length);
            temp.pop();
            if(Array.isArray(temp[count])) {
                arr2.push(temp[count])
            }
            if(temp.length > count + 1) {
                temp = temp[count + 1];
            } else {
                temp = temp[count - 1];
            }
        }
    }
  return arr;
}

steamrollArray([[3, [[4]]], 5]);
Diego Mayer
@Chrono79
Aug 24 2017 20:15
when you do this: temp = temp[count + 1];
you're changing temp
do the console log before closing the while loop
it's undefined
Mohammed Boudad
@matrixersp
Aug 24 2017 20:17
@Chrono79 That's true, thank you
CamperBot
@camperbot
Aug 24 2017 20:17
tekkie7 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
Diego Mayer
@Chrono79
Aug 24 2017 20:17
because it enters the else and count is 0, temp[-1] doesn't exist
CamperBot
@camperbot
Aug 24 2017 20:17
:star2: 4530 | @chrono79 |http://www.freecodecamp.com/chrono79
Diego Mayer
@Chrono79
Aug 24 2017 20:18
:+1:
Try using recursion on that challenge
Mohammed Boudad
@matrixersp
Aug 24 2017 20:20
@Chrono79 Don't know how to use it
Using the built in functions?
Diego Mayer
@Chrono79
Aug 24 2017 20:26
I hope this helps (haven't seen it myself but sometimes they post it here in the chatroom)
Mohammed Boudad
@matrixersp
Aug 24 2017 20:28
Okay, thanks again @Chrono79
CamperBot
@camperbot
Aug 24 2017 20:28
tekkie7 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:warning: tekkie7 already gave chrono79 points
Fernando
@lestairon
Aug 24 2017 20:34

function largestOfFour(arr) {
  // You can do this!
  var largNum = [];
  for (var i = 0; i < arr.length; i++) {
    for (var x = 0; x < arr[i].length; x++) {
      if (arr[i][x] > largNum[i]) {
        largNum.push(arr[i][x]);
      }
    }
  }
  return largNum;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Hm, i think it should work...
But it's not
Moisés Man
@moigithub
Aug 24 2017 20:39
pushing too soon
if instead of push.. u change for an assigment.. i think it would work @lestairon
Brian
@BrianCodes33
Aug 24 2017 20:40
var sumAndMultiply = function(sum, multiply) {

}
sumAndMultiply(13, 12), [1, 12])

Write a function that accepts two parameters (sum and multiply) and find two numbers [x, y], where x + y = sum and x * y = multiply.

Example:

sum = 12 and multiply = 32

In this case, x equals 4 and y equals 8.

x = 4

y = 8

Joseph
@revisualize
Aug 24 2017 20:40
@lestairon try doing a 0 fill on your largNum
Fernando
@lestairon
Aug 24 2017 20:41
@moigithub How?
Joseph
@revisualize
Aug 24 2017 20:41
@lestairon OH! You're doing a .push()
instead of overwriting.
Fernando
@lestairon
Aug 24 2017 20:42
Yeah...
Joseph
@revisualize
Aug 24 2017 20:42
@lestairon So, if 4 is greater than undefined. You're doing a push.
5 is greater than 4. So you're doing a push
[4,5]
Fernando
@lestairon
Aug 24 2017 20:42
It's not pushing anything
Joseph
@revisualize
Aug 24 2017 20:42
then 13 is greater than 5
Fernando
@lestairon
Aug 24 2017 20:43
image.png
Joseph
@revisualize
Aug 24 2017 20:43
@lestairon
@lestairon try doing a 0 fill on your largNum
Fernando
@lestairon
Aug 24 2017 20:44
Change the default value to 0?
Joseph
@revisualize
Aug 24 2017 20:44
@lestairon Care to try it and see what happens?
Fernando
@lestairon
Aug 24 2017 20:45
it pushes all the numbers
Joseph
@revisualize
Aug 24 2017 20:45
at least that way you'd see it .push() something. instead of nothing.
Fernando
@lestairon
Aug 24 2017 20:45
Oh, so i should use something else
Joseph
@revisualize
Aug 24 2017 20:46
@lestairon What if instead of a .push you just overwrote the value?
Fernando
@lestairon
Aug 24 2017 20:48
Like this...?
if (arr[i][x] > largNum[i]) { largNum[i] = arr[i][x]; }
Joseph
@revisualize
Aug 24 2017 20:48
@lestairon try it?
Fernando
@lestairon
Aug 24 2017 20:48
Returns [5]
Joseph
@revisualize
Aug 24 2017 20:49
@lestairon Let me see.
Hmm.. Works for me.
image.png
Joseph
@revisualize
Aug 24 2017 20:56
@lestairon ???
Fernando
@lestairon
Aug 24 2017 20:58
Oh
The thing were those 0's
But...
Why?
Joseph
@revisualize
Aug 24 2017 20:59
@lestairon What is undefinded > 4 ?
Fernando
@lestairon
Aug 24 2017 20:59
undefined...
Is there a way to do that without putting 0s?
Yes, there is
Joseph
@revisualize
Aug 24 2017 21:03
@lestairon yes.
create a new temp variable.
@lestairon You could even do var largNum = new Array(arr.length).fill(0);
@lestairon Or you could use Math.max()
Fernando
@lestairon
Aug 24 2017 21:06
@revisualize Thanks!
CamperBot
@camperbot
Aug 24 2017 21:06
lestairon sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 4448 | @revisualize |http://www.freecodecamp.com/revisualize
Fernando
@lestairon
Aug 24 2017 21:07
I just saw the FCC hint page and...
function largestOfFour(arr) {
  return arr.map(Function.apply.bind(Math.max, null));
}
Really?
Joseph
@revisualize
Aug 24 2017 21:08
@lestairon really.
Fernando
@lestairon
Aug 24 2017 21:08
Well, i need to learn more then haha
Joseph
@revisualize
Aug 24 2017 21:08
@lestairon You'll always need to learn more.
Fernando
@lestairon
Aug 24 2017 21:11
I still can't believe it could be done that easy haha
I'll check the explanation
Why does the .apply not have "()" at the end?
Jason Luboff
@JLuboff
Aug 24 2017 21:14
@lestairon You'd be hard pressed to find any individual who had that solution on their first time doing that challenge unless they had prior programming experience
Fernando
@lestairon
Aug 24 2017 21:15
Yeah, even the intermediate solution seems a little bit hard to do in the first time
luccifer00
@luccifer00
Aug 24 2017 21:28
An iframe which has both allow-scripts and allow-same-origin for its sandbox attribute can remove its sandboxing. this error is something about code-pen?? or it is in my code??
Jason Luboff
@JLuboff
Aug 24 2017 21:28
@luccifer00 Most likely codepen
luccifer00
@luccifer00
Aug 24 2017 21:29
i dont know why sometimes appears and sometimes is not
i dont knwo way my pen yesterday Works perfectly and now, some stuff is dissapear....
way=why..
knwo= know
:smile:
luccifer00
@luccifer00
Aug 24 2017 21:34
i get it.... it is working.. is about size...
Jason Luboff
@JLuboff
Aug 24 2017 21:41
You can edit your posts, just fyi. Just click the three dots next to the time of your post and there is an edit option
LAB-XI
@LAB-XI
Aug 24 2017 22:00
var susan = new Object();
susan.age = 25;
susan.setAge = setAge;

susan.setAge(35);
Can anyone tell me why susan.setAge = setAge; needs to be there for the above to work?
var setAge = function (newAge) {
  this.age = newAge;
};

var susan = new Object();
susan.age = 25;
susan.setAge = setAge;

susan.setAge(35);
This is what I meant to post
Gersho
@Gersho
Aug 24 2017 22:03
var susan = new Object();
isn't that form not recommended ? afaik it's prefered to use var susan = {};
and for your question, if you don't susan.setAge = setAge; where would susan.setAge(35) point to ? since the susan object would only containe the age: 25 data
var susan = new Object();
//susan = {}
susan.age = 25;
//susan = {age:25}
susan.setAge = setAge;
//susan = {age:25, setAge:function (newAge) {  this.age = newAge;} }
LAB-XI
@LAB-XI
Aug 24 2017 22:10
var setAge = function (newAge) {
  this.age = newAge;
};
@Gersho Doesn't the setAge method take of this with the this. placeholder?
Gersho
@Gersho
Aug 24 2017 22:12
when you call susan.setAge(35); it will look inside the susan object under the setAge name, if there's nothing there, it won't work
and while your setAge variable points to this in it's function, there is no link of any kind between that variable and the content of the object susan
if you want to make an object that already has some buit in properties, you want to learn about constructors
LAB-XI
@LAB-XI
Aug 24 2017 22:14
I don't understand. I thought setAge is the method, and that points to the susan, and then age within the Susan object?
Gersho
@Gersho
Aug 24 2017 22:16
no, you make a setAge variable, but it doesn't put it as method of anything
try console.log(susan); at various points of your codd
code
LAB-XI
@LAB-XI
Aug 24 2017 22:17
var setAge = function (newAge) {
  this.age = newAge;
};
Is this not a method?
Gersho
@Gersho
Aug 24 2017 22:19
it's a function in a variable, one would call that a method yes
function person(age) {

    this.age = age;
    this.setAge = function (newAge) {  this.age = newAge;};
}
var susan = new person(25);
susan.setAge(35);
didn't test it but should work the way you want it that way
luccifer00
@luccifer00
Aug 24 2017 22:25

hey , i am getting crazy ...

 $('#all').click(function(){
  var all= document.querySelectorAll('.pet');
  all.style = "display: none";
    console.log(all.length); //return 14
 });
  $('#red').click(function(){
   var red=document.querySelectorAll('.on-line');
     red.style = "display: none";
     console.log(red.length); // do not return anything....
 });
  $('#green').click(function(){
   var green=document.querySelectorAll('.off-line');
     green.style = "display: none";
    console.log(green.length); // return 5
 });

it is just about console.log..... i dont know why the $('#red') selector dosent return anything in the console....
I am not sure if the btn-danger has some hidden property, and i can not use that buttn

i test changing the Green Word to a red, and i can not return the console log....

LAB-XI
@LAB-XI
Aug 24 2017 22:25
@Gersho Ok cool I'll play around with it and see if I can unconfuse myself as to whats going on with this! Thanks for the help!
CamperBot
@camperbot
Aug 24 2017 22:25
lab-xi sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 354 | @gersho |http://www.freecodecamp.com/gersho
Gersho
@Gersho
Aug 24 2017 22:27
@luccifer00 have you tried putting console.log("blabla") to see if the line triggers at all or not ?
luccifer00
@luccifer00
Aug 24 2017 22:29
@Gersho i did it now, with same result.... nothing
if u want to try... maybe it is my browser??? i dont know.... the code is on at the end of the JS
Gersho
@Gersho
Aug 24 2017 22:31
line 12 of your html
<button id¨='red' typ
luccifer00
@luccifer00
Aug 24 2017 22:33
@Gersho what is wrong there?? the rest of id is the same structure
Gersho
@Gersho
Aug 24 2017 22:33
there's a " before the =
luccifer00
@luccifer00
Aug 24 2017 22:33
ooo
i see
fck
thanks @Gersho i was revising but i didnt see the ''
CamperBot
@camperbot
Aug 24 2017 22:34
luccifer00 sends brownie points to @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 355 | @gersho |http://www.freecodecamp.com/gersho
Gersho
@Gersho
Aug 24 2017 22:34
of course you didn't, would be no fun if you did
Fernando
@lestairon
Aug 24 2017 23:16

function repeatStringNumTimes(str, num) {
  // repeat after me
  var currentNum = 0;
  while (currentNum < num) {
    currentNum++;
    return str;
  }
}
repeatStringNumTimes("abc", 3);
Why is it not working? lol
I tried with for too
Jason Luboff
@JLuboff
Aug 24 2017 23:16
@lestairon What are you expecting it to do? You aren't modifying str at all, and thus just returning it as is
Gersho
@Gersho
Aug 24 2017 23:16
return is a one way ticket to stopping the function
if you return, it ends, it doesn't execute multiple return in a while loop like you seem to be expecting
Fernando
@lestairon
Aug 24 2017 23:17
But it works with console.log
Oh, so i should use something else...
Jason Luboff
@JLuboff
Aug 24 2017 23:17

Again...

@lestairon What are you expecting it to do? You aren't modifying str at all, and thus just returning it as is

Gersho
@Gersho
Aug 24 2017 23:17
return is linked to a function(), it exits it, that's how it works
Fernando
@lestairon
Aug 24 2017 23:18
@JLuboff I just want to return the same string num times
Gersho
@Gersho
Aug 24 2017 23:18
well you can use another variable to store stuff while doing your loop, and return that variable once you're done with all yours loops
Jason Luboff
@JLuboff
Aug 24 2017 23:18
@lestairon Thats not how it works. You want to add str to itself num times
Fernando
@lestairon
Aug 24 2017 23:19
Oh, thanks
Gersho
@Gersho
Aug 24 2017 23:19
var blabla = "";
for(whatever){
blabla += "text"}
return blabla;
@lestairon
Gersho
@Gersho
Aug 24 2017 23:24
i'm not sure that's the point of the challenge
kumquatfelafel
@kumquatfelafel
Aug 24 2017 23:24
though it's good to think about how you might write function yourself.
Fernando
@lestairon
Aug 24 2017 23:24

function repeatStringNumTimes(str, num) {
  // repeat after me
  var rtrText = "";
  for (i = 0; i < num; i++) {
    rtrText += str;
  }
  return rtrText;
}
repeatStringNumTimes("abc", 3);
Done :)
kumquatfelafel
@kumquatfelafel
Aug 24 2017 23:25
@Gersho aye, but good to know it exists as well. ;)
Gersho
@Gersho
Aug 24 2017 23:25
:thumbsup: store stuff while doing a loop, that's it :)
@kumquatfelafel and he found the 'expected' solution too !
Fernando
@lestairon
Aug 24 2017 23:26
What does the ? mean?
kumquatfelafel
@kumquatfelafel
Aug 24 2017 23:26
@lestairon conditional operator, sometimes you might also hear it called the ternary operator
Jason Luboff
@JLuboff
Aug 24 2017 23:27
@lestairon Here's a nice short version
function repeatStringNumTimes(str, num) {
  return num ? str.repeat(num) : ""; 
}
Gersho
@Gersho
Aug 24 2017 23:27
a?b:c is the same as if(a)then b else c
Fernando
@lestairon
Aug 24 2017 23:29
Thanks @Gersho @kumquatfelafel and @JLuboff ^^
CamperBot
@camperbot
Aug 24 2017 23:29
lestairon sends brownie points to @gersho and @kumquatfelafel and @jluboff :sparkles: :thumbsup: :sparkles:
:cookie: 623 | @kumquatfelafel |http://www.freecodecamp.com/kumquatfelafel
:cookie: 357 | @gersho |http://www.freecodecamp.com/gersho
:star2: 2168 | @jluboff |http://www.freecodecamp.com/jluboff
Gersho
@Gersho
Aug 24 2017 23:29
@JLuboff oh right, i'll never accept than positive intergers are true
i spend my whole life being told to be careful about units and stuff, that you can't multiply potatoes with carrots and suddenfly 10 === true D:
Jason Luboff
@JLuboff
Aug 24 2017 23:30
@Gersho Ya, but I'd actually probably want return num > 0 ? ... since if num is negative, it will error
lol
Gersho
@Gersho
Aug 24 2017 23:31
error ? depends on how repeat handle negative values
kumquatfelafel
@kumquatfelafel
Aug 24 2017 23:31
@Gersho RangeError
Gersho
@Gersho
Aug 24 2017 23:32
was reading that on zeal :p
Jason Luboff
@JLuboff
Aug 24 2017 23:32
Ya RangeError as @kumquatfelafel mentioned
Fernando
@lestairon
Aug 24 2017 23:33
Oh, so like ? works like
if x ? then a : else b
Jason Luboff
@JLuboff
Aug 24 2017 23:33
Correct
And it can get more complicated then that
Fernando
@lestairon
Aug 24 2017 23:33
How...?
Jason Luboff
@JLuboff
Aug 24 2017 23:34
return a> b? 5 : b > c ? 10 : 2;
So essentially if a is greater then b, return 5, if not, check b is greater than c, return 10 else return 2
Gersho
@Gersho
Aug 24 2017 23:34
and if you add arrow function, it's so messy you'd believe it's php
Jason Luboff
@JLuboff
Aug 24 2017 23:35
:heart: arrow functions
Gersho
@Gersho
Aug 24 2017 23:36
they're nice, but i like readability (so i can understand what i was doing the previous day)
Jason Luboff
@JLuboff
Aug 24 2017 23:36
I think arrow functions are easy to read, ternary not so much
Gersho
@Gersho
Aug 24 2017 23:36
depends on the person i guess
ternary is nice for oneliners
Fernando
@lestairon
Aug 24 2017 23:37
Yeah, i saw arrows too
But still don't know how they work
Gersho
@Gersho
Aug 24 2017 23:37
those are hard to google because you don't even know what to google ^^
Jason Luboff
@JLuboff
Aug 24 2017 23:37
I wouldn't worry about learning them too much at this stage
Fernando
@lestairon
Aug 24 2017 23:37
So, ternary it's good for now
Jason Luboff
@JLuboff
Aug 24 2017 23:38
eh...I'd focus on the basics to be honest
Its good to know how they work, but I wouldn't focus on them
Ugh...this Book Trading App does not look fun lol
Gersho
@Gersho
Aug 24 2017 23:38
there's some rare cases where you have to use ternary instead of if
kumquatfelafel
@kumquatfelafel
Aug 24 2017 23:39

@lestairon more or less. Just be aware that although conditional operator looks very similar to if else statements it isn't exactly the same.

For example, with if else, you can do this.

if(x < 5)
  return x;
else 
  console.log("x is too low");

If you tried to do that with conditional operator...

x < 5 ? return x : console.log("x is too low");

then you'd get an error.

Gersho
@Gersho
Aug 24 2017 23:39
either array.concat or array.reduce, can't remember
what kind of error would you get ?
Jason Luboff
@JLuboff
Aug 24 2017 23:40
I don't think you can return like that?
kumquatfelafel
@kumquatfelafel
Aug 24 2017 23:40
@JLuboff aye
Jason Luboff
@JLuboff
Aug 24 2017 23:41
Aye aye captain!
Gersho
@Gersho
Aug 24 2017 23:41
oh, you can't use ; in the "then" part ?
kumquatfelafel
@kumquatfelafel
Aug 24 2017 23:41
you would need return beforehand, but that isn't the same logic
Gersho
@Gersho
Aug 24 2017 23:41

would

x < 5 ? {return x;} : console.log("x is too low");

work ?

Jason Luboff
@JLuboff
Aug 24 2017 23:41
@kumquatfelafel Hmmm...but couldn't you technically do return console.log('mejasdlkfsa');? It should fire off the console.log and end the function
No, the problem is returtn needs to be in front of the ternary
@kumquatfelafel Ya this works:
function test(x) {
    return x < 5 ? x: console.log('my message');
}

test(6);
Gersho
@Gersho
Aug 24 2017 23:44
and test(4) would return 4 ?
Jason Luboff
@JLuboff
Aug 24 2017 23:44
Correct
kumquatfelafel
@kumquatfelafel
Aug 24 2017 23:44

return x < 5 ? x : console.log("x is too low");

Would run fine, but in the if else statement, we haven't technically returned result of calling console.log(). So if you needed to add more lines of code in latter case, ternary becomes a bit more awkward.

Jason Luboff
@JLuboff
Aug 24 2017 23:44
Ah...thats true.
kumquatfelafel
@kumquatfelafel
Aug 24 2017 23:44
You could, potentially, write a function that carries out the rest of the tasks and put that call as false result.
Gersho
@Gersho
Aug 24 2017 23:45
@kumquatfelafel awkward ? how about
return x<5 ? then() : else();
Jason Luboff
@JLuboff
Aug 24 2017 23:45
If you had functions named those...I think..
Gersho
@Gersho
Aug 24 2017 23:46
that would be a mess to read to have such function names xD
Jason Luboff
@JLuboff
Aug 24 2017 23:46
Yes, it would not be ideal
Gersho
@Gersho
Aug 24 2017 23:46
name one if_ to mess with people reading your code xD
Fernando
@lestairon
Aug 24 2017 23:53
Why people don't use ES6 instead of ES5?
Jason Luboff
@JLuboff
Aug 24 2017 23:53
People do use ES6 but there are still a lot of people using old browsers that don't support it
Jason Luboff
@JLuboff
Aug 24 2017 23:59
I think I use ES6 in all of my Dynamic Web apps thus for (given, these are only for FCC, not production)