These are chat archives for FreeCodeCamp/HelpJavaScript

29th
May 2017
Cynwenn
@Cynwenn
May 29 2017 00:02
@sjames1958gm thanks!
CamperBot
@camperbot
May 29 2017 00:02
cynwenn sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7526 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
JMorris2000
@JMorris2000
May 29 2017 00:03
Can someone help me with Wherefore art thou
Stephen James
@sjames1958gm
May 29 2017 00:04
@Lengzki myNoun, myAdjective, myVerb, myAdverb these four parameters will hold the four words.
Inside the function use what you have learned about string concatenation to build string/sentence and assign to result variable
@JMorris2000 What do you have
Cynwenn
@Cynwenn
May 29 2017 00:11

I'm trying to add a third object to the array and I
In this new function, you want to create a new contact object like bob and mary. Instead of having this object's property values be filled with strings though, set them to the appropriate function parameters passed in.
Add this new contact object to the contacts array.
Call add with whatever first name, last name, phone number, and email arguments you like.
Make sure you call the list function, to check if your new entry is added. And delete any other function that logs output in the console, i.e 'search' function.

More specifically, an object can be added to the end of the array with array[array.length] = object.

var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: "bob.jones@example.com"
};

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: "mary.johnson@example.com"
};

var contacts = [bob, mary];

function printPerson(person) {
    console.log(person.firstName + " " + person.lastName);
}

function list() {
    var contactsLength = contacts.length;
    for (var i = 0; i < contactsLength; i++) {
        printPerson(contacts[i]);
    }
}

/*Create a search function
then call it passing "Jones"*/

var search = function (lastName) {
 var   contactsLength = contacts.length; 
    for (let i = 0; i < contacts.length; i++ ) {


    if (contacts[i].lastName === lastName) {
        printPerson(contacts[i]);
    }
    }


}


var add= function (firstName,  lastName, email, phoneNumber) {
    // attempting to add a new object at contacts.length index (one index after the last used index so should be undefined before this code
    contacts[contacts.length].firstName = firstName;
    contacts[contacts.length].lastName = lastName;
    contacts[contacts.length].email = email;
    contacts[contacts.length].phoneNumber = phoneNumber;




}
add("Joe", "CODING", "je@co.com", "3-2389-3");
list();
Adam Bohannon
@abohannon
May 29 2017 00:23
Can anyone give me a hint on the Mutations challenge? I'm able to compare the two strings using the value indexOf produces, but when the letters aren't in the same order i'm stumped. I assume i have to use a loop to check each character in each string, but I'm still having a hard time understanding the mechanics of loops.

function mutation(arr) {

  var firstArray = arr[0].toLowerCase(),
      secondArray = arr[1].toLowerCase();


if (firstArray.indexOf(secondArray) >= 0){
    return true;
  } else {
    return false;
  }

}

mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"])  // returns false when it should be true;
Moisés Man
@moigithub
May 29 2017 00:25
@abohannon u need to check if EVERY/EACH character of second word is on first word
ur current code checking if the WHOLE second word is on first
walid azzouz
@lewall
May 29 2017 00:27
hy everyone, hope you're doing right !!!
Adam Bohannon
@abohannon
May 29 2017 00:28
@moigithub ok, so I fumbled my way through this for loop and everything is returning properly except for ["hello", "hey"].
function mutation(arr) {

  var firstArray = arr[0].toLowerCase(),
      secondArray = arr[1].toLowerCase();

  for ( var i = 0; i < secondArray.length; i++){
    if (firstArray.indexOf(secondArray[i]) >= 0){
      return true;
    } else {
      return false;
    }
  }
Moisés Man
@moigithub
May 29 2017 00:29
@abohannon ur code returning true too soon
u can use this tool www.pythontutor.com/javascript.html
to track ur code execution (if u cant do mentally)
remember.. return keyword exit the function immediatelly
Adam Bohannon
@abohannon
May 29 2017 00:33
ah man, i "know" that, but keep getting confused on how to fix it. Don't tell me, I'll figure it out.
Andrew
@anblave
May 29 2017 00:33
Hi, I'm in the "Profile Lookup" challenge, I've a doubt: when I try to access an array of object "contacts", I try this way "contacts[i].prop" where "prop" is a variable, but returns nothing, when I try this way "contact[i][prop]" returns the array correctly. Why?
Ravi Kishore Thella
@ravikishorethella
May 29 2017 00:34
@anblave contacts[i].hasOwnProperty(prop)
Moisés Man
@moigithub
May 29 2017 00:35
@Cynwenn contacts is an array.... contacts[contacts.length] dont exist.. so its undefined
undefined.firstName (or whatever property u trying to access) will fail
IF u wanna add a new Object.. first u need to declare/create it
Andrew
@anblave
May 29 2017 00:35
yes, the prop exists
Adam Bohannon
@abohannon
May 29 2017 00:37
@moigithub i guess im confused by mutation(["hello", "neo"]) returns properly, but not mutation(["hello", "hey"])
Andrew
@anblave
May 29 2017 00:37
I mean, can't access whit dot notation, but I do can access bracket notation (sorry my english, I'm from México)
*with
Moisés Man
@moigithub
May 29 2017 00:38
cuz "n" (from "neo" )is NOT inside "hello" it should return false
similar to "y" (from "hey") is not on "hello" it should also return false
Adam Bohannon
@abohannon
May 29 2017 00:38
mutation(["hello", "hey"]) is the only return that's not working for me.
but the loop is checking 3 characters, as demonstrated by the correct return of hello / neo
Moisés Man
@moigithub
May 29 2017 00:39
whtas ur code.. the same posted above? or did u changed anything
also... did u tried the tool posted above ??
Adam Bohannon
@abohannon
May 29 2017 00:39
function mutation(arr) {

  var firstArray = arr[0].toLowerCase(),
      secondArray = arr[1].toLowerCase();

  for ( var i = 0; i < secondArray.length; i++){
    if (firstArray.indexOf(secondArray[i]) >= 0){
      return true;
    } else {
      return false;
    }
  }

/*if (firstArray.indexOf(secondArray) >= 0){
    return true;
  } else {
    return false;
  }*/

  //return firstArray.indexOf(secondArray);

}

mutation(["hello", "hey"]);
Masaki
@masaki1223
May 29 2017 00:39

// Setup
var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    },
    "5439": {
      "album": "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {


  return collection[id][prop];
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
Why is this not showing collection[id][prop]?
Adam Bohannon
@abohannon
May 29 2017 00:40
@moigithub i did, but not sure i'm seeing where it's breaking down
let me look again
Moisés Man
@moigithub
May 29 2017 00:41
that code doing...this
it pick each character of "hey" and check on firstArray variable.. sooo
"h" is on "hello"
"e" is on "hello"
"y" is on "hello"
@abohannon
BUT....
since this "h" is on "hello" evaluates to true... return trueline is executed which ENDS ur function
without checking "e" or "y" (returning too soon)

@masaki1223 updateRecords(5439, "artist", "ABBA");
if id is 5439
collection[5439] will return this

    "5439": {
      "album": "ABBA Gold"
    }

then u trying to access "artist" property of that..
but that object only have an "album" property... so it will return undefined

Adam Bohannon
@abohannon
May 29 2017 00:48
@moigithub so i removed the return so I could see the loop working, which i see now: https://goo.gl/jDTjw5
and predictably as it reaches the end of the secondArray.length (3 loops), it returns undefined since i haven't specified anything to return I assume.
Moisés Man
@moigithub
May 29 2017 00:50
yep all functions return undefined (implicit return) if nothing is specified
Masaki
@masaki1223
May 29 2017 00:50
// Setup
var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    },
    "5439": {
      "album": "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {


  return collection[id];
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
This returns the whole JSON,,,, why is that...
I only want collection[id]to be returned
Moisés Man
@moigithub
May 29 2017 00:51
if "y" is not on "hello" it should return false @abohannon
and only return true after u check if ALL characters are on first word
@masaki1223 test ur code here
repl.it/languages/javascript
after u make it work.. then u can copy/paste to fcc editor
Masaki
@masaki1223
May 29 2017 00:54
@moigithub Oh this website seems working, but fcc doesn't even return correct result. Thx
CamperBot
@camperbot
May 29 2017 00:54
masaki1223 sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3277 | @moigithub |http://www.freecodecamp.com/moigithub
Andrew
@anblave
May 29 2017 01:00
Please read the commented line (if I'm being annoying just tell me, I'm trying to undestand)
//Setup
var contacts = [
    {
        "firstName": "Akira",
        "lastName": "Laine",
        "number": "0543236543",
        "likes": ["Pizza", "Coding", "Brownie Points"]
    },
    {
        "firstName": "Harry",
        "lastName": "Potter",
        "number": "0994372684",
        "likes": ["Hogwarts", "Magic", "Hagrid"]
    },
    {
        "firstName": "Sherlock",
        "lastName": "Holmes",
        "number": "0487345643",
        "likes": ["Intriguing Cases", "Violin"]
    },
    {
        "firstName": "Kristian",
        "lastName": "Vos",
        "number": "unknown",
        "likes": ["Javascript", "Gaming", "Foxes"]
    }
];


function lookUpProfile(firstName, prop){
// Only change code below this line
  for (var i = 0; i < contacts.length; i++) {
    if (firstName == contacts[i].firstName) {
      if (contacts[i].hasOwnProperty(prop)) {
        return contacts[i].prop; //Why don´t work this way, but work does work with "contacts[i][prop]"
      } else {
        return "No such property";
      }
    }

  }
  return "No such contact";
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Kristian", "lastName");
Moisés Man
@moigithub
May 29 2017 01:02

when using dot notation.. whatever follow the dot .. mean its literally an actual object property with exactly that name @anblave
ie:

myObj = {
  name: "boo",
  tails : 3,
  legs: 8
}

myObj.name will return "boo"
if u compare.. name EXIST on myObj

Andrew
@anblave
May 29 2017 01:03
ohhhhh, sorry, so is looking literaly for "prop" but doesn't exists
Ravi Kishore Thella
@ravikishorethella
May 29 2017 01:03
@anblave
if (contacts[i].firstName == firstName) {
if (contacts[i].hasOwnProperty(prop)) {
return contacts[i][prop];
}
else {
return "No such property";
}
}
Moisés Man
@moigithub
May 29 2017 01:04
@anblave aye...
prop is a variable which "holds" the real property name,
when working with variables u need to use brackets
Andrew
@anblave
May 29 2017 01:04
thanks a lot, I'm dumb xP
Adam Bohannon
@abohannon
May 29 2017 01:11
@moigithub finally got it! Thanks for the help
function mutation(arr) {

  var firstArray = arr[0].toLowerCase(),
      secondArray = arr[1].toLowerCase();

  for ( var i = 0; i < secondArray.length; i++){
    if (firstArray.indexOf(secondArray[i]) == -1){
     return false;
    } 

  }
  return true;

/*if (firstArray.indexOf(secondArray) >= 0){
    return true;
  } else {
    return false;
  }*/

  //return firstArray.indexOf(secondArray);

}

mutation(["zyxwvutsrqponmlkjihgfedcba", "qrstu"]);
CamperBot
@camperbot
May 29 2017 01:11
abohannon sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3278 | @moigithub |http://www.freecodecamp.com/moigithub
Moisés Man
@moigithub
May 29 2017 01:12
:+1:
__SharifTarver__
@Sharifdesigns22
May 29 2017 01:20

// Example
var ourArr = [ 9, 10, 11, 12];
var ourTotal = 0;

for (var i = 0; i < ourArr.length; i++) {
  ourTotal += ourArr[i];
}

// Setup
var myArr = [ 2, 3, 4, 5, 6];

// Only change code below this line

var total = 0;
for( var i = 0; i <myArr.length; i++)
{
  total += myArr[i];
}
I got this right but I don't understand how total = 20 , could someone explain?
FlashHero
@FlashHero
May 29 2017 01:22
@Sharifdesigns22 you are adding the values of myArr
 total += myArr[i];
Moisés Man
@moigithub
May 29 2017 01:22
2+3+4+5+6 = ?? @Sharifdesigns22
Long Nguyen
@longnt80
May 29 2017 01:28
@moigithub 20
Moisés Man
@moigithub
May 29 2017 01:29
:) @longnt80
Long Nguyen
@longnt80
May 29 2017 01:29
@moigithub jk :smile:
__SharifTarver__
@Sharifdesigns22
May 29 2017 01:30
Thanks! it's easy to overthink these problems.
shaunams630
@shaunams630
May 29 2017 01:30
hey guys, I'm having trouble getting this code to pick up variables a, b and c, can someone tell me why?

function switchOfStuff(val) {
var answer = "";
// Only change code below this line
var a = "apple";
var b = "bird";
var c = "cat";
var d = "stuff";

switch(val){

case 1:
  answer = a;
 break;

case 2:
answer = b;
  break;

case 3:
 answer = c;
  break;


default:
 answer = d;

}

// Only change code above this line
return answer;
}

// Change this value to test
switchOfStuff(1);

it's just a simple switch condition
it should call apple, bird, cat and stuff as the default
Long Nguyen
@longnt80
May 29 2017 01:32
@Sharifdesigns22 you can go here and click forward to see how the loop works: https://goo.gl/2sGYii
Moisés Man
@moigithub
May 29 2017 01:33
which test fails ? @shaunams630
shaunams630
@shaunams630
May 29 2017 01:34
when I test varable a it works but not the others
Moisés Man
@moigithub
May 29 2017 01:34
others like ?? @shaunams630
shaunams630
@shaunams630
May 29 2017 01:35
case 1, case 2, and case 3 are failing
Moisés Man
@moigithub
May 29 2017 01:35
which test (on the bottom left part of ur screen) have a red mark @shaunams630
shaunams630
@shaunams630
May 29 2017 01:36
dont see it
Moisés Man
@moigithub
May 29 2017 01:36
then ... make a screenshot
Alex
@alextran1502
May 29 2017 01:39
Can anyone give me a hint on Chunky Monkey algorithm? I have been sitting on it for a day and haven't figured it out yet
Ivan Leo
@yaaaas
May 29 2017 01:40

Hey guys, Im a bit confused with my code for Mutations where we need to use indexof to loop through a given string and compare it with another string.

function mutation(arr) {

var target = arr[0].toLowerCase();
var test = arr[1].toLowerCase();

for(i = 0; i < test.length ; i ++){
if (target.indexOf(test[i]) < 0 )
return false;

}
return true;
}
mutation(["hello", "hey"]);

This code only works if I remove the { } for the if conditional operator
i.e
Alex
@alextran1502
May 29 2017 01:41
@yaaaas where is your else?
Ivan Leo
@yaaaas
May 29 2017 01:42
My else is the return true!
Alex
@alextran1502
May 29 2017 01:42
@yaaaas
function mutation(arr) {
var target = arr[0].toLowerCase();
var test = arr[1].toLowerCase();
for(i = 0; i < test.length ; i ++){
if (target.indexOf(test[i]) < 0 )
return false;
} else {
return true;
}
}
mutation(["hello", "hey"]);
@yaaaas then put it down maybe?
Ivan Leo
@yaaaas
May 29 2017 01:43
I get an "Unexpected Token Error" If I include the else though
I copied your code exactly @alextran1502
Moisés Man
@moigithub
May 29 2017 01:45
curly brackets determine a block of code

soo if u have

function someName(){
 /// code here
}

whatever inside those { .. } means are PART of the function
many instructions/commands have uses blocks of code
like for/loops or IF's @yaaaas

for ( ..... ) {
   // code here will be executed multiple times
}
Frank McCroy
@fmccroy
May 29 2017 01:45
@alextran1502 I just finished ChunkyMonkey.. I made a for loop that looped for the number of times arr.length could be divided by size, and then started slicing the arr into chunks
@alextran1502 A hard part for me was getting an even number for my for loop to use. I used a lot of console.log’s to see where the problems were
Alex
@alextran1502
May 29 2017 01:47

@yaaaas

function mutation(arr) {
var target = arr[0].toLowerCase();
var test = arr[1].toLowerCase();
for(i = 0; i < test.length ; i ++){
  if (target.indexOf(test[i]) < 0 ){
    return false;
  } else {
    return true;
  }
  }
}
mutation(["hello", "hey"]);

here, that was a missing }, remember to indent your code properly, it would help you with seeing missing tokens.

@fmccroy thank you sir, I will think more about the problem
CamperBot
@camperbot
May 29 2017 01:48
alextran1502 sends brownie points to @fmccroy :sparkles: :thumbsup: :sparkles:
:cookie: 323 | @fmccroy |http://www.freecodecamp.com/fmccroy
Moisés Man
@moigithub
May 29 2017 01:51
@yaaaas if no {} are specified.. then the command/instruction will TAKE the immediate next ONE line as part of its code block
jenilkansara
@jenilkansara
May 29 2017 01:58

Hey guys, Please help me out, the first letters are not converting to uppercase, neither the toLowerCase is working.
function titleCase(str) {
var splitString = str.split(" ");

for(i=2;i<splitString.length;i++) {
var wordSplit = splitString[i].split("");
wordSplit[0].toUpperCase();
for(x=1;x<wordSplit.length;x++)
{
wordSplit[x].toLowerCase();
}
splitString[i] = wordSplit.join("");
}
var finalString = splitString.join(" ");
return finalString;
}

titleCase("I'm a little tea pot");

Moisés Man
@moigithub
May 29 2017 02:02
strings methods like toUpperCase() return a new string
u not doing anything with it.. u need to re-assign it @jenilkansara
Ryan Williams
@Ryanwfile
May 29 2017 02:04
Can someone explain why I'm getting the TypeError cannot read property 'setState' of undefined for the following code, any help is greatly appreciated
class Points extends React.Component {
  constructor(props){
    super(props)
    this.state = {}
  }

  componentDidMount() {
    return axios.get('https://fcctop100.herokuapp.com/api/fccusers/top/recent')
      .then(function(dataR) {    
      //error is most likely with the code below
      this.setState({
        userInfo : dataR.data
      })      
    });  
  }
  render() {
    if(!this.state.userInfo) return <p>Loading...</p>
    return (
      <div>
        <h1>{this.state.userInfo} </h1>
      </div>
    )
  }
}
Moisés Man
@moigithub
May 29 2017 02:04
cuz the context of this changes @Ryanwfile
this inside the then callback its NOT pointing to the same object/class
u can store the reference of this on another variable .. ie var that = this
use bind.. or arrow function
Ryan Williams
@Ryanwfile
May 29 2017 02:06
@moigithub Thanks for the help, I initially copied most of the code using arrow functions and it didn't work then either
CamperBot
@camperbot
May 29 2017 02:06
ryanwfile sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3279 | @moigithub |http://www.freecodecamp.com/moigithub
jenilkansara
@jenilkansara
May 29 2017 02:07
@moigithub Oh thank you!
CamperBot
@camperbot
May 29 2017 02:07
jenilkansara sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3280 | @moigithub |http://www.freecodecamp.com/moigithub
vaghelaj
@vaghelaj
May 29 2017 02:16
Hi
what is the meaning of string with encoding text with the proper escape sequences ?
jrvscm
@jrvscm
May 29 2017 02:21
can someone inform me why this isnt true for "hello", "hey"?;

function mutation(arr) {

var sub1= arr[0].toLowerCase();
var sub2= arr[1].toLowerCase();

for (var i = 0; i < sub2.length; i++){
if (sub1.indexOf(sub2[i]) == -1){

return false;          

} 

else return true;

}
}
mutation(["HELLO", "hey"]);

i meant false**
ive changed the variables around quite a bit and it still never passes the first challenge but all the rest pass.
Moisés Man
@moigithub
May 29 2017 02:30

@jrvscm

if (sub1.indexOf(sub2[i]) == -1){
        return false;          
} 
else return true;

return exit the function immediatelly

jrvscm
@jrvscm
May 29 2017 02:31
@moigithub Ahh, exactly. should have notice d that. thank you much.
CamperBot
@camperbot
May 29 2017 02:31
jrvscm sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3281 | @moigithub |http://www.freecodecamp.com/moigithub
Nick Gray
@nicholasnbg
May 29 2017 02:31
@Lwave you need to have " " around your cases
eg case "a"
jrvscm
@jrvscm
May 29 2017 02:32
@vaghelaj they want you to use the escape sequences properly in a string.
@moigithub don't I want it to escape immediately if its false?
Moisés Man
@moigithub
May 29 2017 02:37
@jrvscm if false.. yes
Nick Gray
@nicholasnbg
May 29 2017 02:37
@jrvscm your else doesn't have its code inside {}
Moisés Man
@moigithub
May 29 2017 02:38
but... first check ur code doing is
"hello" contains "h" <-- this will evaluates as true... soo
this code will be executed else return true; <- which will break ur loop without checking "e" or "y" @jrvscm
jrvscm
@jrvscm
May 29 2017 02:38
@moigithub ahh i see, thank you.
CamperBot
@camperbot
May 29 2017 02:38
jrvscm sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:warning: jrvscm already gave moigithub points
rugano
@rugano
May 29 2017 02:52
Hello campers
Nick Gray
@nicholasnbg
May 29 2017 02:54
hey
rugano
@rugano
May 29 2017 02:54
What is exactly wrong and how can i correct it in my weather app here? https://codepen.io/Njue/full/QvPaMo
Nick Gray
@nicholasnbg
May 29 2017 02:56
hmm I'm not familiar with angular, gonna step away from that one, might get some better support in https://gitter.im/angular/angular.js?source=suggested-menu
CyberBrick
@CyberBrick
May 29 2017 03:00
Hey all
I need some assistance with Iterating with JavaScript For Loops,
makista2
@makista2
May 29 2017 03:01
please help
newbie me
about Escape Sequences in Strings
CyberBrick
@CyberBrick
May 29 2017 03:02
Here is my code, I'm getting Only [] in my return statement

/ Example
var ourArray = [];

for (var i = 0; i < 5; i++) {
ourArray.push(i);
}

// Setup
var myArray = [];

// Only change code below this line.
for (var i = 0; i < 5; i++) {
ourArray.push(i);

}

makista2
@makista2
May 29 2017 03:02
can anyone enlightened how to escape this?
CyberBrick
@CyberBrick
May 29 2017 03:02
Also the example is only returning "5".
Claudio Restifo
@Marmiz
May 29 2017 03:03
@CyberBrick you probably want to push into myArray:
// Setup
var myArray = [];
// Only change code below this line.
for (var i = 0; i < 5; i++) {
ourArray.push(i);
}
Nick Gray
@nicholasnbg
May 29 2017 03:03
@CyberBrick shouldn't you be pushing to myArray , not ourArray?
CyberBrick
@CyberBrick
May 29 2017 03:05
Ahhh, the "little" things Thanks @Marmiz @nicholasnbg . But whats the deal with the example returning onlt 5
CamperBot
@camperbot
May 29 2017 03:05
cyberbrick sends brownie points to @marmiz and @nicholasnbg :sparkles: :thumbsup: :sparkles:
:cookie: 321 | @nicholasnbg |http://www.freecodecamp.com/nicholasnbg
:cookie: 898 | @marmiz |http://www.freecodecamp.com/marmiz
Claudio Restifo
@Marmiz
May 29 2017 03:05
@makista2 what have you tried so far?
Nick Gray
@nicholasnbg
May 29 2017 03:06
@CyberBrick try console log ouyArray, mine returned this:
console.log(ourArray) Array [ 0, 1, 2, 3, 4 ]
i think 5 refers to how many entries in the array possibly?
Nick Forlivio
@whackdev
May 29 2017 03:08
can anyone take a look at my pen> I can't get the items to center in the rows for the life of me!
https://codepen.io/whackdev/pen/ybQrYa
Long Nguyen
@longnt80
May 29 2017 03:09
@whackdev vertical center?
Nick Forlivio
@whackdev
May 29 2017 03:09
@longnt80 yes
Long Nguyen
@longnt80
May 29 2017 03:09
that's a tricky one :smile:
Nick Gray
@nicholasnbg
May 29 2017 03:09
@whackdev I hate css stuff, but you might want to look into display: flex stuff (https://beta.freecodecamp.com/en/challenges/css-flexbox/introduction-to-the-css-flexbox-challenges)
Nick Forlivio
@whackdev
May 29 2017 03:09
@longnt80 i've searched and implemented a bunch of options
Long Nguyen
@longnt80
May 29 2017 03:10
@whackdev yes flexbox can help
Nick Forlivio
@whackdev
May 29 2017 03:10
@nicholasnbg I tried that but let me check your resource
Nick Gray
@nicholasnbg
May 29 2017 03:10
gl, im off for a bit
Mohammed Boudad
@matrixersp
May 29 2017 03:10
Someone help me with this (Seek and Destroy)
function theSame() {
  return arguments;
}
function destroyer(arr) {
  // Remove all the values
  var arr2 = [];
  arr2 = arr.filter(theSame);
  return arr2;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Long Nguyen
@longnt80
May 29 2017 03:12
@whackdev add this to the container div:
display: flex;
align-items: center;
Nick Forlivio
@whackdev
May 29 2017 03:12
@longnt80 I'll try that thanks
CamperBot
@camperbot
May 29 2017 03:12
whackdev sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 318 | @longnt80 |http://www.freecodecamp.com/longnt80
Nick Forlivio
@whackdev
May 29 2017 03:14
@longnt80 I thougt I had tried that before but it worked this time, I must've put it in the wrong place
Claudio Restifo
@Marmiz
May 29 2017 03:14

@Tekkie7 what are you trying to achieve with this?

function theSame() {
  return arguments;
}

In this case arguments is an empty object

Long Nguyen
@longnt80
May 29 2017 03:14
@whackdev yeah, could be
Mohammed Boudad
@matrixersp
May 29 2017 03:16
@Marmiz trying to create a new filtered array. I use arguments to filter it
Claudio Restifo
@Marmiz
May 29 2017 03:17
@Tekkie7 but argument in there is an empty object. Did you gave a look at the argument documentation?
Frank McCroy
@fmccroy
May 29 2017 03:17
How do I check for NaN’s on Falsy Bouncer, when isNan keeps filtering out strings that I need?

function bouncer(arr) {
// Don't show a false ID to this bouncer.
var newArr=[];
newArr = arr.filter(function (val)
{
if (( val!=='') && (val!==false) && (val!==null) && (val!==0) && (val!==undefined) && (isNaN(val)!==true))
return true;
});

console.log ("New Array: " + newArr);
return newArr;
}

bouncer([7, "ate", "", false, 9]);

Long Nguyen
@longnt80
May 29 2017 03:24
@fmccroy you only need !isNaN(val)
......&& !isNaN(val)
Frank McCroy
@fmccroy
May 29 2017 03:28
@longnt80 I tried it, but it still strips out strings. They may not be numbers, but I need them. It needs to strip out NaN’s specifically
Long Nguyen
@longnt80
May 29 2017 03:28
@fmccroy btw, Boolean is also a function already so you can do this:
function bouncer(arr) {
   return arr.filter(Boolean);
}
Frank McCroy
@fmccroy
May 29 2017 03:33
@longnt80 I started with return and the logic inside it, but got confused and changed it to an “if” statement. The isNaN is still stripping out my strings, preventing them from going into the array
Long Nguyen
@longnt80
May 29 2017 03:34
@fmccroy let me see
Frank McCroy
@fmccroy
May 29 2017 03:35
function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  var newArr=[];
  newArr = arr.filter(function (val)
  {
   if (( val!=='') && (val!==false) && (val!==null) && (val!==0) && (val!==undefined) && !isNaN(val)) return true;
                      });

  console.log ("New Array: " + newArr);
  return newArr;
}

bouncer([7, "ate", "", false, 9]);
Claudio Restifo
@Marmiz
May 29 2017 03:41
@fmccroy I strongly suggest you to use the Boolean method. NaN is notoriously unreliable and a pain to deal with in JS.
It's often used only on number.isNaN()
Frank McCroy
@fmccroy
May 29 2017 03:42
function bouncer(arr) {
return arr.filter(Boolean);
} will do what I need, without the rest of the logic?
Claudio Restifo
@Marmiz
May 29 2017 03:42
But if you want to go for the "long" road I'd suggest you to split the val into String and Number, and check NaN only on second case :)
Nick Gray
@nicholasnbg
May 29 2017 03:43
@fmccroy why do you need to check val is a number if you are also checking for strings as well?
Claudio Restifo
@Marmiz
May 29 2017 03:43
@fmccroy Boolean doc
Nick Gray
@nicholasnbg
May 29 2017 03:44
and yes return arr.filter(Boolean); would work
Long Nguyen
@longnt80
May 29 2017 03:47
@fmccroy ok with your logic above, you need to have an else if for any val that is a "string"
use typeof val === "string"
Frank McCroy
@fmccroy
May 29 2017 03:48
@Marmiz I read what you linked earlier and completely missed that is dealt with Nan’s, undefineds, etc for me. @longnt80 I scrapped the if statement and just used the Boolean method like you tried to tell me earlier ;)
Long Nguyen
@longnt80
May 29 2017 03:49
@fmccroy you can still do the if statement above, it will help you to understand the type of values
@fmccroy
function bouncer(arr) {
// Don't show a false ID to this bouncer.
var newArr=[];
newArr = arr.filter(function (val) {

    if ( (val!=='') && (val!==false) && (val!==null) && (val!==0) && (val!==undefined) && !isNaN(val) ) {
    return true;
    }
    else if (typeof val === "string") {
      return true;
    }

});

console.log ("New Array: " + newArr);
return newArr;

}

bouncer([7, "ate", "", false, 9]);
Frank McCroy
@fmccroy
May 29 2017 03:52
So if I had kept going with the if statement, I would have had to separate the strings out, or isNaN would have kept filtering them?
MadeForBacon
@MadeForBacon
May 29 2017 03:56
can anyone help me?
myVar should equal 88
myVar = myVar should be changed
Use the ++ operator
Do not change code above the line
Im having a problem with this? would someone point me in the right place?
Long Nguyen
@longnt80
May 29 2017 03:57
which challenge is this?
MadeForBacon
@MadeForBacon
May 29 2017 03:57
@longnt80 126
Frank McCroy
@fmccroy
May 29 2017 03:57
@longnt80 @Marmiz @nicholasnbg Thanks to everyone for the help, I hope I think of the Boolean function in the future when needed.
CamperBot
@camperbot
May 29 2017 03:57
fmccroy sends brownie points to @longnt80 and @marmiz and @nicholasnbg :sparkles: :thumbsup: :sparkles:
:cookie: 319 | @longnt80 |http://www.freecodecamp.com/longnt80
:cookie: 322 | @nicholasnbg |http://www.freecodecamp.com/nicholasnbg
:cookie: 900 | @marmiz |http://www.freecodecamp.com/marmiz
Long Nguyen
@longnt80
May 29 2017 03:58
@MadeForBacon is that everything?
myVar should equal 88
myVar = myVar should be changed
Use the ++ operator
Do not change code above the line
MadeForBacon
@MadeForBacon
May 29 2017 03:58
yeah
Kris Baillargeon
@krisb1220
May 29 2017 03:59
an array the same thing as a list in python?
Claudio Restifo
@Marmiz
May 29 2017 03:59
@fmccroy the main thing you have to remember (as a general rule of thumb) is to always look for official Docs. Then you'll read and remember :)
Long Nguyen
@longnt80
May 29 2017 03:59
can you give the link
Kris Baillargeon
@krisb1220
May 29 2017 03:59
is*
MadeForBacon
@MadeForBacon
May 29 2017 04:00
yupp
Long Nguyen
@longnt80
May 29 2017 04:00
@MadeForBacon can you give me the link
Kris Baillargeon
@krisb1220
May 29 2017 04:00
thanks man @MadeForBacon
CamperBot
@camperbot
May 29 2017 04:00
krisb1220 sends brownie points to @madeforbacon :sparkles: :thumbsup: :sparkles:
:cookie: 127 | @madeforbacon |http://www.freecodecamp.com/madeforbacon
Kris Baillargeon
@krisb1220
May 29 2017 04:00
oops
MadeForBacon
@MadeForBacon
May 29 2017 04:01
thanks!
haha
Kris Baillargeon
@krisb1220
May 29 2017 04:01
i gotta stop coming in this chatroom late at night i cant ever tell whos talking to me LOL
Claudio Restifo
@Marmiz
May 29 2017 04:01
@krisb1220 I don't know PY but Array in JS are list-like Object with no fixed type
can someone help pls?
Kris Baillargeon
@krisb1220
May 29 2017 04:02
Ah thanks it differs slightly but for all intense purpose they seem similar lol thanks @Marmiz
CamperBot
@camperbot
May 29 2017 04:02
krisb1220 sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 901 | @marmiz |http://www.freecodecamp.com/marmiz
Baibhav Gautam
@baibhavx
May 29 2017 04:02
@Norsi47 3 ways to do the same thing:
a = a + 1
a += 1
a++
Claudio Restifo
@Marmiz
May 29 2017 04:02
@Norsi47 you should use the ++ notation.
Norsi47
@Norsi47
May 29 2017 04:03
ya i tried tht
Claudio Restifo
@Marmiz
May 29 2017 04:03
@krisb1220 anyway you can look at the official documentation here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
Baibhav Gautam
@baibhavx
May 29 2017 04:04

The question wants you to use the third one. So get rid of

myVar = myVar + 1;

and write

myVar++

instead. @Norsi47

Long Nguyen
@longnt80
May 29 2017 04:04
@MadeForBacon
look at what @baibhavx wrote above
vasatrya
@vasatrya
May 29 2017 04:04
Can anyone help please? I am stuck on the Profile Lookup problem, under Basic JS (i believe its problem 219)
MadeForBacon
@MadeForBacon
May 29 2017 04:04
@longnt80 thanks
CamperBot
@camperbot
May 29 2017 04:04
madeforbacon sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 320 | @longnt80 |http://www.freecodecamp.com/longnt80
Baibhav Gautam
@baibhavx
May 29 2017 04:05
Hey @longnt80 :)
Long Nguyen
@longnt80
May 29 2017 04:05
@vasatrya yeah, I think all beginners have problem with Profile Lookup
@baibhavx what's up
vasatrya
@vasatrya
May 29 2017 04:06
my code is:
Baibhav Gautam
@baibhavx
May 29 2017 04:06
just sayiin hi
vasatrya
@vasatrya
May 29 2017 04:06
for (var i = 0; i < contacts.length; i++) {
if (firstName === contacts[i].firstName && contacts[i].hasOwnProperty(prop) === true) {
return contacts[i][prop];
}
else if (firstName !== contacts[i].firstName) {
return "No such contact";
}
else if (contacts[i].hasOwnProperty(prop) === false) {
return "No such property";
}
}
Long Nguyen
@longnt80
May 29 2017 04:07
@baibhavx what's up is one kind of hello too :smile:
vasatrya
@vasatrya
May 29 2017 04:07
at the moment, the last 2 else if statements work, but not the 1st. but if i remove the last 2 else if statements, the first one works. not sure where im off
Markus Ivancsics
@ivancsicsmarkus
May 29 2017 04:07
@vasatrya You are returning too early.
Long Nguyen
@longnt80
May 29 2017 04:07
@vasatrya .hasOwnProperty(prop) this is wrong
Markus Ivancsics
@ivancsicsmarkus
May 29 2017 04:08

@vasatrya THis way:

else if (firstName !== contacts[i].firstName) {
return "No such contact";
}

You would return the first time when the firstname does not match.

Ken Haduch
@khaduch
May 29 2017 04:08
@vasatrya - you should group your return of the property or the return of "No such property" under the condition where you have a match on the firstName... then watch out for returning "No such contact" while you still have contacts in the list.
Markus Ivancsics
@ivancsicsmarkus
May 29 2017 04:09
@longnt80 You should only return
  • when you find the property
  • when you find the name but not the property
  • when you did not find the name (outside of the loop)
vasatrya
@vasatrya
May 29 2017 04:13
So i need a nested if statement?
Kris Baillargeon
@krisb1220
May 29 2017 04:13
Whoever answered my question about JS who said they knew nothing of Python: Holy. Crap. It should be called PyScript LOL
only real difference is some minimal syntax but a lot of that is even the same
Markus Ivancsics
@ivancsicsmarkus
May 29 2017 04:17
@vasatrya Yes.
@krisb1220 Not really.
Nurbek
@NurbekGithub
May 29 2017 04:18

Hello! I need some help with Steamroller challenge js. The code:
function steamrollArray(arr) {
// I'm a steamroller, baby
for(var i in arr) {
if(Array.isArray(arr[i])){
arr.splice(i,0,arr[i].pop());
if(arr[i+1].length === 0) {
arr.splice(i+1,1);
}
i = i-1;
}
}
return arr;
}

steamrollArray([1, [2], [3, [[4]]]]);
returns error: Cannot read peoperty 'length' of undefined. Can someone help me, please?

Markus Ivancsics
@ivancsicsmarkus
May 29 2017 04:20
@NurbekGithub Use this instead of for in:
for(var i = 0; i < arr.length; i++) {
@NurbekGithub Because for in is not realiable a lot of times at more complex tasks.
@NurbekGithub Also a for var loop gives you much more control.
Nick Gray
@nicholasnbg
May 29 2017 04:22
alright need some regex help here, https://beta.freecodecamp.com/en/challenges/regular-expressions/specify-upper-and-lower-number-of-matches
let ohStr = "Ohhhhhhh no";
let ohRegex = /h{3,6}\s/i; // Change this line
let result = ohRegex.test(ohStr);
Nurbek
@NurbekGithub
May 29 2017 04:22
@ivancsicsmarkus hmm, interisting. it was some help. thanks. I will try to solve the problem further
CamperBot
@camperbot
May 29 2017 04:22
:cookie: 548 | @ivancsicsmarkus |http://www.freecodecamp.com/ivancsicsmarkus
nurbekgithub sends brownie points to @ivancsicsmarkus :sparkles: :thumbsup: :sparkles:
DrK971
@DrK971
May 29 2017 04:24
hello everybody
in the
Storing Values with the Assignment Operator challenge
I'm thinking that this --->var a = 7;
var b = var a;
this is the right code
but only this works ---> var a = 7;
var b = 7;
can somebody explain?
thanks
Oh, I just found out
Claudio Restifo
@Marmiz
May 29 2017 04:28
@DrK971 you don't have to re-assign the var name once declared:
var b = var a;
DrK971
@DrK971
May 29 2017 04:28
var a = 7;
var b = a; seems to do it . Maybe it was a bug
Claudio Restifo
@Marmiz
May 29 2017 04:28
@DrK971 no it was a syntax error your first draft.
DrK971
@DrK971
May 29 2017 04:29
thanks @Marmiz It makes sense now, I didn't understand why var a = 7;
var b = 7; was working
CamperBot
@camperbot
May 29 2017 04:29
drk971 sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 902 | @marmiz |http://www.freecodecamp.com/marmiz
Cristhian Hernandez
@Cristhian-Hernandez
May 29 2017 04:36
guys i need help with this counting cards problem
switch (card) {
case (card <= 6 && card >= 2):
count += 1;
break;
case (card <= 9 && card >= 7):
count += 0;
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count -= 1;
break;
}
im starting to think this code does nothing at all HAHA
Claudio Restifo
@Marmiz
May 29 2017 04:38

@DrK971 well the difference between:

var a = 7;
var b = a;

Is that b is "linked" to the value of a. So if later I set a=22 b will always be equal to a (so b will be 22)
While

var a = 7;
var b = 7;

Means that a an b are independent from each other. So if later I give a=22 b will still be 7
Makes sense?

Markus Ivancsics
@ivancsicsmarkus
May 29 2017 04:39
@Cristhian-Hernandez Use if/else statement instead of switch!
@Cristhian-Hernandez Switch would make it too complex. It does not nescessary. Use if!
Claudio Restifo
@Marmiz
May 29 2017 04:40
@Cristhian-Hernandez Well, after you need to do something with the count variable.
@ivancsicsmarkus I strongly disagree. This is a perfect example of using a switch statement. The advantage is that will make the code far more readable and maintainable :)
Cristhian Hernandez
@Cristhian-Hernandez
May 29 2017 04:41
@Marmiz yep, thats where the second part of thecae comes in but it really does nothing:(

switch (count) {
case (count === 0 || count < 0):
count += " Hold";
break;
default:
count += " Bet";
break;
}

return count;

@ivancsicsmarkus I tried but it is too messy, i can't make it work as intended either :/
part of the code*
Claudio Restifo
@Marmiz
May 29 2017 04:49
@Cristhian-Hernandez anyway you need to tweak the switch statement for multiple cases:
function cc(card) {
  switch (card) {

    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
      count++ ;
     break; 

      // you got the idea

  }
    // then do something with count
    if (count >0)  return something

}
vasatrya
@vasatrya
May 29 2017 04:52
thanks @ivancsicsmarkus thanks @khaduch thanks @longnt80 i finally got it! simpler than i thought now that i got the solution haha..
CamperBot
@camperbot
May 29 2017 04:52
vasatrya sends brownie points to @ivancsicsmarkus and @khaduch and @longnt80 :sparkles: :thumbsup: :sparkles:
:cookie: 321 | @longnt80 |http://www.freecodecamp.com/longnt80
:cookie: 551 | @ivancsicsmarkus |http://www.freecodecamp.com/ivancsicsmarkus
:star2: 2923 | @khaduch |http://www.freecodecamp.com/khaduch
vasatrya
@vasatrya
May 29 2017 04:54
took longer than i thought, but it was because of a silly overlook (of course)
Cristhian Hernandez
@Cristhian-Hernandez
May 29 2017 05:02
thanks @Marmiz Wow it worked! that is sort of what i though of at first but because im too lazy to type more i decided to create that formula. I thought it was possible HAHAHA! well, that was really helpful, thank you!
CamperBot
@camperbot
May 29 2017 05:02
cristhian-hernandez sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:cookie: 903 | @marmiz |http://www.freecodecamp.com/marmiz
Claudio Restifo
@Marmiz
May 29 2017 05:03
@Cristhian-Hernandez ARD --> always read documentation!! :D
glad it worked in the end :sparkles:
Cristhian Hernandez
@Cristhian-Hernandez
May 29 2017 05:05
cheers 😃🙌
Bashir Harrell
@bookofbash
May 29 2017 05:05
Hi All
Joseph
@revisualize
May 29 2017 05:05
Counting Cards is a challenge where your function will receive a card parameter. You're supposed to increment or decrement the global count variable according to the card's value
If the value of the card parameter is 2, 3, 4, 5 or 6 you need to increment the global variable count.
If the value of the card parameter is 10, 'J', 'Q', 'K' or 'A' you need to decrement the global variable count.
...
Then the function will return a string with the current count and the string "Bet" if the count is positive, or "Hold" if the count is zero or negative.
The current count and the player's decision ("Bet" or "Hold") should be separated by a single space.
...
...
Things to note: You should NOT be returning based on the value of the card. The value of card should only be adding or subtracting 1 from the global variable count.
The value of the global variable count is used to determine the return statement.
Bashir Harrell
@bookofbash
May 29 2017 05:06
Does anyone know how to prevent codepen from using HTTPS?
Joseph
@revisualize
May 29 2017 05:06
If you have HTTPS Everywhere.. You need to turn it off.
Bashir Harrell
@bookofbash
May 29 2017 05:07
How does that work?
Claudio Restifo
@Marmiz
May 29 2017 05:07
@bookofbash as a simple workaround you can navigate manually to http:....
Bashir Harrell
@bookofbash
May 29 2017 05:07
@Marmiz I tried to manually type it in, and in the past it worked. Today it isn't working.
Bashir Harrell
@bookofbash
May 29 2017 05:16
R.Ragupathi
@rrpathi
May 29 2017 05:32
i am stuck
Increment a Number with JavaScript
Markus Kiili
@Masd925
May 29 2017 05:33
@rrpathi What have you done?
Dave Reichert
@davidreichert
May 29 2017 05:47
need help with Using Objects for Lookups
Markus Kiili
@Masd925
May 29 2017 05:53
@davidreichert Post the code you have done.
Dave Reichert
@davidreichert
May 29 2017 05:54
// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
  val = {
    "alpha":"Adams",
    "bravo":"Boston",
    "charlie":"Chicago",
    "delta":"Denver",
    "echo":"Easy",
    "foxtrot":"Frank"
  };

  // Only change code above this line
  return result;
}

// Change this value to test
phoneticLookup("charlie");
Markus Kiili
@Masd925
May 29 2017 05:55
@davidreichert You should not change the name of the variable that holds the object. It needs to be var lookup = {...
@davidreichert You need to access the object property value with syntax obj[key] and assign the value to result variable. What is the object and where lurks the key?
sarthakveggalam
@sarthakveggalam
May 29 2017 05:59
Hi. I need help with the Inventory Update algorithm challenge.
Mohammed Boudad
@matrixersp
May 29 2017 06:00
I got stuck here, someone help me plz
function theSame() {
  return arguments;
}
function destroyer(arr) {
  // Remove all the values
  var arr2 = [];
  arr2 = arr.filter(function() {
    return ;
  });
  return arr2;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
sarthakveggalam
@sarthakveggalam
May 29 2017 06:01
//jshint esversion:6
function updateInventory(arr1, arr2) {
    // All inventory must be accounted for or you're fired!
    for(let [i,[quantity,item]] of arr1.entries()){    
      for(let [i2,[quantity2,item2]] of arr2.entries()){

          if(item === item2){
              quantity += quantity2;
//              console.log(`the item is ${item2} and its quantity is ${quantity}`);
            arr1[i][0] = quantity;
          }


//           console.log(`the item is ${item} and its quantity is ${quantity} at ${i}`);

      }
      return arr1;

//         console.log(quantity,item); 
    }

}

// Example inventory lists
var curInv = [
    [21, "Bowling Ball"],
    [2, "Dirty Sock"],
    [1, "Hair Pin"],
    [5, "Microphone"]
];

var newInv = [
    [2, "Hair Pin"],
    [3, "Half-Eaten Apple"],
    [67, "Bowling Ball"],
    [7, "Toothpaste"]
];

updateInventory(curInv, newInv);
Can someone tell me why only Bowling Ball gets updated and not hair pin?
Markus Kiili
@Masd925
May 29 2017 06:01
@Tekkie7 The filter callback function needs a parameter that holds the arr element being iterated by filter.
@Tekkie7 Inside the callback, you need to return false if that parameter value is found on destroyers arguments, and true otherwise.
Dave Reichert
@davidreichert
May 29 2017 06:02
still stuck. What am I not seeing?
// Setup
function phoneticLookup(val) {
  var result = "";

  // Only change code below this line
  var lookup = {
    "alpha":"Adams",
    "bravo":"Boston",
    "charlie":"Chicago",
    "delta":"Denver",
    "echo":"Easy",
    "foxtrot":"Frank"
  };
lookup.val = result;
  // Only change code above this line
  return result;
}

// Change this value to test
phoneticLookup("charlie");
Markus Kiili
@Masd925
May 29 2017 06:03
@davidreichert That looks for property key "val".
Not the key stored in parameter val.
And the assignment goes from right side to left.
Vedant Kashyap
@vedant15188
May 29 2017 06:03

Hey guys... I was wondering if anyone could help me on getting started with the roman numerals challenge... here's a link to the challenge...

https://www.freecodecamp.com/challenges/roman-numeral-converter

I have no idea how to go about it even after reading the resource from the roman numerals.

Markus Kiili
@Masd925
May 29 2017 06:05
@vedant15188 A popular way is to store the basis of Roman numerals on two arrays in letters and numbers, and then solve it by iterating the array of numbers and generating the result on the fly.
Vedant Kashyap
@vedant15188
May 29 2017 06:05
ummm okay I kinda get what ou mean... Lemme try...
thanks @Masd925
CamperBot
@camperbot
May 29 2017 06:05
vedant15188 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4152 | @masd925 |http://www.freecodecamp.com/masd925
Markus Kiili
@Masd925
May 29 2017 06:06
@vedant15188 Basis means just that you need only to consider some of the numbers.
Vedant Kashyap
@vedant15188
May 29 2017 06:11
okay @Masd925 but how do i get the program to display 40 or 39? they kinda differ from the way the rest of the numbers are written
Markus Kiili
@Masd925
May 29 2017 06:12
@Tekkie7 Boolean function doesn't help here.
Dave Reichert
@davidreichert
May 29 2017 06:13
@Masd925 I still don't get it
Markus Kiili
@Masd925
May 29 2017 06:14
@vedant15188 You need an arrays like var NUM = [1000,900,500,...]and var ROM = ['M','CM','D',...]. Then you first check how many times 1000 fits into num and generate M's. Then 900 etc.
Mohammed Boudad
@matrixersp
May 29 2017 06:14
How do I test for both arguments ?
function destroyer(arr) {
// Remove all the values
var arr2 = [];
var args = Array.prototype.slice.call(arguments);
args.shift();
arr2 = arr.filter(function() {
return Boolean(args);
});
return arr2;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
Markus Kiili
@Masd925
May 29 2017 06:14
@davidreichert You need to use bracket notation because the key needs to be evaluated from a variable.
@Tekkie7 Look at MDN filter page for simple examples of filter usage.
Vedant Kashyap
@vedant15188
May 29 2017 06:15
@Masd925 if i have to include roman numerals for 900 or stuff like that then it would be a super long array cuz by that logic I would have to store 4,9,19 etc. too.
Markus Kiili
@Masd925
May 29 2017 06:15
@Tekkie7 The number of arguments is not known, so a loop of some kind is in order.
@vedant15188 Array has 13 elements.
@vedant15188 And it is the simplest and clearest way.
Dave Reichert
@davidreichert
May 29 2017 06:17
That's dumb. Thanks @Masd925
CamperBot
@camperbot
May 29 2017 06:17
davidreichert sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4153 | @masd925 |http://www.freecodecamp.com/masd925
Vedant Kashyap
@vedant15188
May 29 2017 06:18
@Masd925 okay lemme try to code that... let's see what happens :)
Brett Burtson
@bburtson
May 29 2017 06:25
anyone have any insight on "No repeats please" ... I'm having difficulty coming up with an approach that is efficient.... I understand the concept of permutation.. i just cant wrap my head around an approach that isn't a nightmare.
Markus Kiili
@Masd925
May 29 2017 06:25
@bburtson Most people google some efficient algorithm for making the permutations.
Brett Burtson
@bburtson
May 29 2017 06:26
this isn't going to go against the "write your own code"?
Markus Kiili
@Masd925
May 29 2017 06:28
@bburtson Yes, but figuring out your own algorithm for making permutations is too hard for most people and is mostly just math. So in this rare case I would not consider it cheating.
Brett Burtson
@bburtson
May 29 2017 06:28
okay
are you familiar with that challenge?
Markus Kiili
@Masd925
May 29 2017 06:28
@bburtson Yes.
Brett Burtson
@bburtson
May 29 2017 06:28
Thanks by the way.
Could i give you my current broad strokes and you could tell me if you think im headed in the right direction?
Markus Kiili
@Masd925
May 29 2017 06:29
@bburtson Sure.
Brett Burtson
@bburtson
May 29 2017 06:31
My thoughts are to create some function that matches duplicates chars...
and
maybe loop different str combonations against the predicate
this sounds silly right?
so sudo ... is something like
Markus Kiili
@Masd925
May 29 2017 06:34
@bburtson I just implemented an algorithm for generating all the possible permutations and checked for validity (no repeating consecutive letters) on the fly.
Brett Burtson
@bburtson
May 29 2017 06:34
impressed
lol
i suppose
im struggling with how to create the permutations
Markus Kiili
@Masd925
May 29 2017 06:35
@bburtson I would recommend finding some existing algorithm and implement it with JS. Then try to include the validity check.
Brett Burtson
@bburtson
May 29 2017 06:36
okay thanks I appreciate it.
That sounds easy enough ... just you saying "generate" => "check for validity" really helps
rugano
@rugano
May 29 2017 06:47
Hello campers,I am trying to call an api,kindly correct me
Mohammed Boudad
@matrixersp
May 29 2017 06:50
@Masd925 It took me so long to find a solution for it although I don't think it's the best
function destroyer(arr) {
  // Remove all the values
  var arr2 = [];
  var args = Array.prototype.slice.call(arguments);
  args.shift();  
  arr2 = arr.filter(function(previous, next) {
    var isFound = true;
    for(var i = 0; i <= args.length; i++) {
      if(args[i] == arr[next]){
        isFound = false;
      } 
    }
    return isFound;
  });
  return arr2;
}

destroyer([1, 2, 3, 1, 2, 3], 2, 3);
rugano
@rugano
May 29 2017 06:51
$.getJSON('https://api.darksky.net/forecast/ad83b7c20374b190f9520c95dad20652' + '?callback=?').done(displayWeather);
Markus Kiili
@Masd925
May 29 2017 06:52
@Tekkie7 You could avoid shifting with var args = Array.prototype.slice.call(arguments,1);
@Tekkie7 Inside the callback, you could avoid the flag variable by returning when you know the return value. Also makes it somewhat more efficient.
@Tekkie7 You could also use indexOf instead of looping the arguments.
@Tekkie7 Also you can avoid the arr2 variable by return arr.filter(...);
Mohammed Boudad
@matrixersp
May 29 2017 06:57
@Masd925 Okay, thank you :)
CamperBot
@camperbot
May 29 2017 06:57
tekkie7 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4154 | @masd925 |http://www.freecodecamp.com/masd925
Anshul Adlakha
@anshuladlakha
May 29 2017 07:10
@rugano You are not insterting any location. After the API key you need to put longitude and latitude separated by commas.
sandeep mohanty
@sakm
May 29 2017 07:14
in the Concatenating Strings with Plus Operator
var myStr=" This is the start. " + "This is the end.";
why is this showing an error.""
?
Xarri Jorge
@xarrijorge
May 29 2017 07:15
@sakm check the punctuation, they matter also.
sandeep mohanty
@sakm
May 29 2017 07:16
it is asking myStr should have a value of This is the start. This is the end.
i cant understand the error
Xarri Jorge
@xarrijorge
May 29 2017 07:17
@sakm post your code
function mutation(arr) { var f=0,i=0; arr[0]=arr[0].toLowerCase; arr[1]=arr[1].toLowerCase; for(i=0;i<arr[0].length && f!=-1;i++) f=arr[1].indexOf(arr[0][i]); if(f!=-1) for(i=0;i<arr[1].length && f!=-1;i++) f=arr[0].indexOf(arr[1][i]); if(f==-1) return false; else return true; } mutation(["hello", "hey"]);
This is mutation
which is not working in some cases
any clues?
sandeep mohanty
@sakm
May 29 2017 07:18
@kodinglife var myStr=" This is the start. " + "This is the end.";
Xarri Jorge
@xarrijorge
May 29 2017 07:18
@D3V4N5H just for info, there is an Array.includes method that might be handy
@sakm refresh and see
ManpreetSingh93
@ManpreetSingh93
May 29 2017 07:19
How to do Counting cards challenge.

var count = 0;

function cc(card) {
// Only change code below this line

return "Change Me";
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

sandeep mohanty
@sakm
May 29 2017 07:19
okz
Devansh Trivedi
@D3V4N5H
May 29 2017 07:19
@kodinglife Thanks. I followed the description.
CamperBot
@camperbot
May 29 2017 07:19
:cookie: 467 | @kodinglife |http://www.freecodecamp.com/kodinglife
d3v4n5h sends brownie points to @kodinglife :sparkles: :thumbsup: :sparkles:
Xarri Jorge
@xarrijorge
May 29 2017 07:20
@D3V4N5H did it work?
Devansh Trivedi
@D3V4N5H
May 29 2017 07:20
really don't think it makes a difference
lemme try and report
Xarri Jorge
@xarrijorge
May 29 2017 07:21
@D3V4N5H :thumbsup:
Markus Kiili
@Masd925
May 29 2017 07:22
@ManpreetSingh93 Check value of card and change count. Then test count and make a return based on it.
Devansh Trivedi
@D3V4N5H
May 29 2017 07:22
@kodinglife so i replaced .indexOf with .includes but no progress that way
Claudio Restifo
@Marmiz
May 29 2017 07:23
@D3V4N5H have you checked the suggested method of string.indexOf?
Instead of arr.indexOf?
Devansh Trivedi
@D3V4N5H
May 29 2017 07:23
yes @Marmiz
this is the one
Xarri Jorge
@xarrijorge
May 29 2017 07:23
@D3V4N5H you may to restructure the entire code when using a new method. Just want to point out that it is available though.
Nasridean
@Nasridean
May 29 2017 07:23
Hello, everyone! could you break down this code?
var str = 'To be, or not to be, that is the question.';
var count = 0;
var pos = str.indexOf('e');

while (pos !== -1) {
  count++;
  pos = str.indexOf('e', pos + 1);
}

console.log(count);
Claudio Restifo
@Marmiz
May 29 2017 07:24
@D3V4N5H your attempt involves array .indexOf
It's easier than you think :)
Nasridean
@Nasridean
May 29 2017 07:24
especially the role of count
Claudio Restifo
@Marmiz
May 29 2017 07:24
'Blue Whale'.indexOf('Blue');     // returns  0
'Blue Whale'.indexOf('Blute');    // returns -1
Mohammed Boudad
@matrixersp
May 29 2017 07:24
@Masd925 this seems better
function destroyer(arr) {
  // Remove all the values
  var args = Array.prototype.slice.call(arguments);
  args.shift();  
  return arr.filter(function(previous, next) {
    if(args.indexOf(arr[next]) > -1) {
       return false;
    }
    return true;
  });
}
Markus Kiili
@Masd925
May 29 2017 07:25
@Tekkie7 You can still refactor it a bit:
function destroyer(arr) {
  var args = Array.prototype.slice.call(arguments,1);
  return arr.filter(function(val) {
    return args.indexOf(val)===-1;
  });
}
Devansh Trivedi
@D3V4N5H
May 29 2017 07:26
@Marmiz yes.
oh, how so?
Xarri Jorge
@xarrijorge
May 29 2017 07:26
@Nasridean you are searching through str and returning the amount of times the letter "e" appears.
Mohammed Boudad
@matrixersp
May 29 2017 07:26
@Masd925 Thank you. That was very helpful
CamperBot
@camperbot
May 29 2017 07:26
tekkie7 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:warning: tekkie7 already gave masd925 points
Markus Kiili
@Masd925
May 29 2017 07:26
@Tekkie7 Slicing arguments has some browser optimization problems, so it is better to use ES6 Array.from or use a loop:
function destroyer(arr) {
  var args = [];
  for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);

  return arr.filter(function(val) {
    return args.indexOf(val)===-1;
  });
}
Mohammed Boudad
@matrixersp
May 29 2017 07:27
@Masd925 Yeah I see
Nasridean
@Nasridean
May 29 2017 07:27
but, how come does count work?
Claudio Restifo
@Marmiz
May 29 2017 07:35

@D3V4N5H that's what you have to figure it out yourself.
But in theory you have two strings: let's call them x and y.
Than all you can do is loop for each letter of y and as soon as one of y letter is missing from x return false.
Otherwise you can return true since all the letters in y are inside x.

You were on the right track but over-complicated yourself with a variable that switch between -1 and 0

Devansh Trivedi
@D3V4N5H
May 29 2017 07:36
ok no flag variables now
Nasridean
@Nasridean
May 29 2017 07:41
@D3V4N5H I am also doing this challenge
Here is what I came up with so far
```js
function destroyer(arr) {
  var args = [];
  for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);

  return arr.filter(function(val) {
    return args.indexOf(val)===-1;
  });
 }
}

mutation(["hello", "Hello"]);
Appuchadinesh
@appuchadinesh
May 29 2017 07:41
var myStr; // Change this line
myStr=" I am a \"double quoted\" string inside \"double quotes\".";
Nasridean
@Nasridean
May 29 2017 07:42
Could anyone tell me, please what's wrong with my code?
Appuchadinesh
@appuchadinesh
May 29 2017 07:42
why i dint get I am a "double quoted" string inside "double quotes". this output
heroiczero
@heroiczero
May 29 2017 07:42
@appuchadinesh i think you have to use single quotes outside and double quotes inside
Ghulam Shabir
@ghulamshabir
May 29 2017 07:43
@appuchadinesh remove space in the beginning
Markus Kiili
@Masd925
May 29 2017 07:43
@Nasridean Just one extra brace there.
Ghulam Shabir
@ghulamshabir
May 29 2017 07:43
@Masd925 hey bro how are you doing ?
Markus Kiili
@Masd925
May 29 2017 07:43
@Nasridean Should work when you remove it.
@ghulamshabir Fine. How about you?
Appuchadinesh
@appuchadinesh
May 29 2017 07:44
ya u are crct @ghulamshabir now works fine ...thank u all
CamperBot
@camperbot
May 29 2017 07:44
appuchadinesh sends brownie points to @ghulamshabir :sparkles: :thumbsup: :sparkles:
:star2: 1920 | @ghulamshabir |http://www.freecodecamp.com/ghulamshabir
Ghulam Shabir
@ghulamshabir
May 29 2017 07:44
I am fine too but came here on fcc after 2-3 months
@appuchadinesh glad that helped
Markus Kiili
@Masd925
May 29 2017 07:45
@ghulamshabir Welcome back :sparkles:
Ghulam Shabir
@ghulamshabir
May 29 2017 07:45
@Masd925 thanks bro I think I forgot everything lol
CamperBot
@camperbot
May 29 2017 07:45
ghulamshabir sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4155 | @masd925 |http://www.freecodecamp.com/masd925
Appuchadinesh
@appuchadinesh
May 29 2017 07:47
if we learn once that wont forget again we see that we came know and we can easily understand @ghulamshabir
Ghulam Shabir
@ghulamshabir
May 29 2017 07:48
@appuchadinesh thanks for motivation, I hope I get upto speed soon
CamperBot
@camperbot
May 29 2017 07:48
ghulamshabir sends brownie points to @appuchadinesh :sparkles: :thumbsup: :sparkles:
:warning: @appuchadinesh's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
Javier Pons
@JavierPons
May 29 2017 07:54
hi guys!
May Kittens Devour Your Soul
@diomed
May 29 2017 07:54

Javier Pons
@JavierPons
May 29 2017 07:54
how about this code:
George Kech.
@georgemitnick
May 29 2017 07:55
Guys, do you know if it's possible to use an external api with ajax?
Javier Pons
@JavierPons
May 29 2017 07:55
function greeting(name){
return 'Hello, ' + name +'!';
}
when name is undefined should prompt "Hello!" and no "Hello undefined!"
should I use if?
Alexandre Conrady
@Aberoom
May 29 2017 07:56
@JavierPons so you're going to have to enter a condition, if statement works, that checks whether or not the name variable is null/undefined etc.
Javier Pons
@JavierPons
May 29 2017 07:57
@Aberoom great!
Markus Kiili
@Masd925
May 29 2017 07:57
@JavierPons You could also check arguments.length, because not passing an argument and passing undefined is not the same.
Alexandre Conrady
@Aberoom
May 29 2017 07:58
@JavierPons @Masd925 but if they passed undefined, wouldn't arguments.length be equal to 1, same as if they actually passed their name?
George Kech.
@georgemitnick
May 29 2017 07:58
@Masd925 Markus, I think it's not possible to use an external api with pure Ajax. Am I right?
Javier Pons
@JavierPons
May 29 2017 07:58
@Aberoom work, thanks!
CamperBot
@camperbot
May 29 2017 07:58
javierpons sends brownie points to @aberoom :sparkles: :thumbsup: :sparkles:
:cookie: 362 | @aberoom |http://www.freecodecamp.com/aberoom
Alexandre Conrady
@Aberoom
May 29 2017 07:58
@JavierPons You're welcome buddy happy coding :)
Javier Pons
@JavierPons
May 29 2017 07:59
:+1:
Markus Kiili
@Masd925
May 29 2017 07:59
@Aberoom Yes, that is why I suggest checking if(arguments.length===0) if you need to check if no argument is passed.
kris28
@kris28
May 29 2017 08:02
myVar = myVar should be changed... please help
Alexandre Conrady
@Aberoom
May 29 2017 08:03
@kris28 well myVar is myVar, so no need to equate them. Are you trying to change the value? Something like myVar += myVar; ?
kris28
@kris28
May 29 2017 08:04
@Aberoom thanj
@Aberoom thanks , thee problem is trying to make myvar = 88
CamperBot
@camperbot
May 29 2017 08:04
kris28 sends brownie points to @aberoom :sparkles: :thumbsup: :sparkles:
:cookie: 363 | @aberoom |http://www.freecodecamp.com/aberoom
Alexandre Conrady
@Aberoom
May 29 2017 08:05
@kris28 No problem have fun :)
kris28
@kris28
May 29 2017 08:05

var myVar = 87;

// Only change code below this line
myVar = myVar + 1;

@Aberoom

George Kech.
@georgemitnick
May 29 2017 08:05
Can anyone help me? Can I use an external api with ajax to do the Random Quote Machine challenge?
Alexandre Conrady
@Aberoom
May 29 2017 08:06
@kris28 you can also use the += notation to make it shorter,
myVar += 1; //is the same as myVar = myVar + 1
raju
@rajureddy2010
May 29 2017 08:06
hi ,,
kris28
@kris28
May 29 2017 08:06
thank you
raju
@rajureddy2010
May 29 2017 08:07
how to apply Array sort and reverse methods @ one time
badalsaibo
@heyDante
May 29 2017 08:07
@georgemitnick You can use any API you want.
George Kech.
@georgemitnick
May 29 2017 08:08
but how am I going to add the link of the api to the code?
Saif Ur Rahman
@saifsmailbox98
May 29 2017 08:09
what is getCoords()?
Alexandre Conrady
@Aberoom
May 29 2017 08:09
@rajureddy2010 you can chain methods together with a dot. You've got to put them in the right order though. .sort isn't a very efficient method for large arrays, so it would be best to find a different way.
George Kech.
@georgemitnick
May 29 2017 08:09

@heyDante this:

  xmlhttp.open("GET", "http://api.forismatic.com/api/1.0/", true);

doesn't work

@heyDante Also, are you a fan of Clerks? :D
badalsaibo
@heyDante
May 29 2017 08:13
@georgemitnick Sorry man, I'm not much into API stuffs.
And i'm hearing Clerks for the first time :smile:
George Kech.
@georgemitnick
May 29 2017 08:13
@heyDante One of the main characters was called Dante.
badalsaibo
@heyDante
May 29 2017 08:14
Yep, just googled it!
rotanimec
@rotanimec
May 29 2017 08:14
has anyone done Steamroller recently?
i get the right output but it says its not correct?
Blauelf
@Blauelf
May 29 2017 08:20
Do not use global variables.
rotanimec
@rotanimec
May 29 2017 08:20
ah is that illegal
Blauelf
@Blauelf
May 29 2017 08:20
They won't reset between subsequent function calls.
rotanimec
@rotanimec
May 29 2017 08:21
kk thx
Blauelf
@Blauelf
May 29 2017 08:21
So you get the right result, but the second call won't.
rotanimec
@rotanimec
May 29 2017 08:22
ok it went through! thx
Blauelf
@Blauelf
May 29 2017 08:22
:+1:
Stephen James
@sjames1958gm
May 29 2017 08:29
@kris28 myVar++;
This is the same as
myVar += 1;
myVar = myVar + 1;
Ertan Kara
@ertankara
May 29 2017 08:30
@sjames1958gm how do i send my code in that format
Javier Pons
@JavierPons
May 29 2017 08:30

code: function askPolitely(sentence){
if(sentence.slice(sentence.length-1) === '?'){

  return sentence + ' please?';

} else{
return sentence;
}
} what I have to add in the If for take out '?' if the end of the phrase doesn't have 'please' and add 'please?'. And what to do if the end of the string have 'please?' return only string of sentence?

Stephen James
@sjames1958gm
May 29 2017 08:31
@hiimnew Use three ``` then shift-enter, paste code, shift-enter, then three ```
https://forum.freecodecamp.com/t/markdown-code-formatting/18391
Ertan Kara
@ertankara
May 29 2017 08:32
@sjames1958gm Thank you
CamperBot
@camperbot
May 29 2017 08:32
hiimnew sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7527 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Javier Pons
@JavierPons
May 29 2017 08:32
like this:

'''function askPolitely(sentence){
if(sentence.slice(sentence.length-1) === '?'){

  return sentence + ' please?';

} else{
return sentence;
}
}

// EXAMPLE TESTS

console.log(askPolitely("May I borrow your pencil?"));
// OUTPUT: "May I borrow your pencil please?"

console.log(askPolitely("May I borrow your pencil please?"));
// OUTPUT: "May I borrow your pencil please?"

console.log(askPolitely("My name is Grace Hopper."));
// OUTPUT: "My name is Grace Hopper."
'''

CamperBot
@camperbot
May 29 2017 08:32
:bulb: to format code use backticks! ``` more info
Ertan Kara
@ertankara
May 29 2017 08:32

function lookUpProfile(firstName, prop){
for (var i = 0; i < contacts.length; i++) {

  if (firstName === contacts[i].firstName) {

    if (prop === "firstName") {

      return contacts[i].firstName;

    } else if (prop === "lastName") {

      return contacts[i].lastName;

    } else if (prop === "number") {

      return contacts[i].number;

    } else if (prop === contacts[i].likes) {

      return contacts[i].likes;        
    }

    else {

      return "No such property";
    }

  } else {

    return "No such contacts";
  }
}

}

it kinda failed but can someone help on this exercise
Stephen James
@sjames1958gm
May 29 2017 08:33
@hiimnew
Your loop has can only return, so it will not reach the second contact. You cannot return no such contact until all contacts have been checked
Ertan Kara
@ertankara
May 29 2017 08:37
@sjames1958gm i don't understand exactly where that problem occurs wish i had a debugger :)
Saif Ur Rahman
@saifsmailbox98
May 29 2017 08:38
how to save the data in a html element into a variable?
Stephen James
@sjames1958gm
May 29 2017 08:38
@hiimnew There are sites like jsbin, or repl.it or pythontutor js mode that allow better debugging
Ertan Kara
@ertankara
May 29 2017 08:39
@sjames1958gm Thanks i will check it
CamperBot
@camperbot
May 29 2017 08:39
hiimnew sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:warning: hiimnew already gave sjames1958gm points
Stephen James
@sjames1958gm
May 29 2017 08:39
@hiimnew If you had a stack of business cards when would you decide that you didn't have a contact?
@saifsmailbox98 textContent is a property that holds the value in an element
Saif Ur Rahman
@saifsmailbox98
May 29 2017 08:40
@sjames1958gm okay.
Ertan Kara
@ertankara
May 29 2017 08:40
@sjames1958gm Yes i know what you mean I need to check every contact in the list but i have no idea how to proceed the loop to the next contact
Bashir Harrell
@bookofbash
May 29 2017 08:41

Anyone can tell what is wrong with mu openweatherapi call?

$(document).ready(function(){
  //location data
  $.getJSON("https://freegeoip.net/json/?callback=?", function(json) {
    console.log(json);
    var city, country;
    var cityName = json.city;
    var countryName = json.country_name;
    var long =json.longitude;
    var lata =json.latitude;
    $("#city").html(cityName +"," + " " + countryName);
    $("#longitude").html(long);
    $("#latitude").html(lata);
    //weather data
    var weatherApi="https://api.openweathermap.org/data/2.5/weather?lat=" + lata + "&lon=" + long +"&units=metric" + "&appid=7fe882a1ac171b12b3acea5655a2e097";
    console.log(weatherApi);
   $.getJSON(weatherApi, function(data) {
     console.log(data);
      //set tempC as current temperature
   var tempC = data.main.temp;
   var tempF = tempC * (9/5)+32;
   var weather = data.weather;
   $("#tempature").html(tempC);
   console.log (tempC + " C &deg;");
   console.log (tempF + " F &deg;");
   console.log (weather);
  });
  });
});

I keep getting this error <Failed to load resource: net::ERR_CONNECTION_REFUSED

CamperBot
@camperbot
May 29 2017 08:41
:bulb: to format code use backticks! ``` more info
Stephen James
@sjames1958gm
May 29 2017 08:41
@hiimnew You don't have to have every return inside the loop. You don't have to have an else to the firstName check
@bookofbash Open weather doesn't support https, at least for free
Bashir Harrell
@bookofbash
May 29 2017 08:43
@sjames1958gm Great, so since codepen switched to https, then it is out. I guess i will try my luck with darksky. Do you know of any others that work well with https?
Kelechi Chinaka
@ke1echi
May 29 2017 08:43
var noIfsNoButs = function (a,b) {
  switch(a, b) {
    case (a > b):
    return a + " is greater than " + b;
    case (a < b):
    return a + " is smaller than " + b;
    default:
    return a + " is equal to " + b;
  }
}
am solving a 8kyu kata that states no use of if || ? and i want to solve with switch it just keeps giving me the default value..wat am i doing wrong @sjames1958gm @Blauelf
Stephen James
@sjames1958gm
May 29 2017 08:43
@bookofbash I guess you could try a CORS proxy that does support https
@kelechichinaka the value of a,b is b and switch compares with ===
Javier Pons
@JavierPons
May 29 2017 08:45

'''function askPolitely(sentence){
if(sentence.slice(sentence.length-1) === '?'){
if(sentence.slice(sentence.length-1) === 'please?'){
return sentence;
}else{
var arr =" ";
var str = sentence.split();
var dele = str.pop();
return dele + ' please?';
}

} else{
return sentence;
}
}'''

CamperBot
@camperbot
May 29 2017 08:45
:bulb: to format code use backticks! ``` more info
Stephen James
@sjames1958gm
May 29 2017 08:45
@JavierPons
var p = "please?";
if (sentence.slice(sentence.length-1) === '?' && sentence.slice(-p.length) !== p) {
    return sentence.slice(0, -1) + p;
}
return sentence;
Javier Pons
@JavierPons
May 29 2017 08:46

```function askPolitely(sentence){
if(sentence.slice(sentence.length-1) === '?'){
if(sentence.slice(sentence.length-1) === 'please?'){
return sentence;
}else{
var arr =" ";
var str = sentence.split();
var dele = str.pop();
return dele + ' please?';
}

} else{
return sentence;
}
}```
whats wrong within this code?

Saif Ur Rahman
@saifsmailbox98
May 29 2017 08:46
how to put the temperature and the ° F on the same line
https://codepen.io/saifsmailbox98/pen/RVmyWo
Victor Popescu
@VicPopescu
May 29 2017 08:46
@saifsmailbox98 both of them need to be inline-block or inline
Kelechi Chinaka
@ke1echi
May 29 2017 08:47
i dont understand @sjames1958gm
Blauelf
@Blauelf
May 29 2017 08:47

@kelechichinaka switch(a,b) is same as switch(b). You could try either

switch(true) {
  case a > b:

or (in my opinion less abusing switch)

switch((a>b)-(b>a)) {
  case 1: // greater
  case 0: // equal, or one of them non-comparable like strings or NaN
  case -1: // less
Saif Ur Rahman
@saifsmailbox98
May 29 2017 08:47
@VicPopescu okay thanks
aceroAD
@aceroAD
May 29 2017 08:48

hi, im abslutly stuck in the falsy bouncer chanllenge, this is the code i have

function bouncer(arr) {

  var cont = [];

  for (var i = 0; i < arr.length ; i++){

    if (arr[i] === 0 || arr[i] === false || arr[i] === null || arr[i] === undefined || arr[i] === "" || arr[i] !== arr[i]){

      cont = arr.splice(i,1);
        arr = cont;
    }
   return arr;
}
}

i don't know how to do it, i tried with .filter and with .splice but i dont understand specially how .filter works

Kelechi Chinaka
@ke1echi
May 29 2017 08:49
oook @Blauelf
Blauelf
@Blauelf
May 29 2017 08:49
@aceroAD Instead of arr = arr.splice(i, 1);, you could do arr.splice(i, 1); i-=1; (last part adjusting the index, as you otherwise would skip the next element), though I would prefer not using splice, but something like filter.
Stephen James
@sjames1958gm
May 29 2017 08:50
@saifsmailbox98 You can use display:inline; for the divs
Saif Ur Rahman
@saifsmailbox98
May 29 2017 08:51
@sjames1958gm okay thanks
CamperBot
@camperbot
May 29 2017 08:51
saifsmailbox98 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7528 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
May 29 2017 08:51
@JavierPons if(sentence.slice(sentence.length-1) === 'please?'){ this cannot be true because the first is only one letter
@JavierPons return dele + ' please?'; this is adding a string to an array - not good
Kelechi Chinaka
@ke1echi
May 29 2017 08:52
i understand now, switch(a, b) is a bad idea @Blauelf
Blauelf
@Blauelf
May 29 2017 08:53
@kelechichinaka Comma operator is rarely useful, or at least it rarely produces code that is obvious when read.
Saif Ur Rahman
@saifsmailbox98
May 29 2017 08:53
have a look, click on the temperature it will pop up the temperature in degree C, how can I chop it upto only two decimal places?
Stephen James
@sjames1958gm
May 29 2017 08:53
@kelechichinaka
var a = 10;
var b = 20
a,b === 20
true
aceroAD
@aceroAD
May 29 2017 08:53
@Blauelf but i dont understand the filter.
Blauelf
@Blauelf
May 29 2017 08:53
@saifsmailbox98 Do you know Number.prototype.toFixed?
Saif Ur Rahman
@saifsmailbox98
May 29 2017 08:54
@Blauelf no
Javier Pons
@JavierPons
May 29 2017 08:54
@sjames1958gm whats do: sentence.slice(-p.length) !== p)?
slice(-p.length)?
Blauelf
@Blauelf
May 29 2017 08:54
@saifsmailbox98 (3.1415926535).toFixed(2) would output "3.14"
Stephen James
@sjames1958gm
May 29 2017 08:54
@JavierPons It tests if the end of sentence is not "please?"
Saif Ur Rahman
@saifsmailbox98
May 29 2017 08:54
@Blauelf thanks that helped
CamperBot
@camperbot
May 29 2017 08:54
saifsmailbox98 sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4260 | @blauelf |http://www.freecodecamp.com/blauelf
Kelechi Chinaka
@ke1echi
May 29 2017 08:55
hmm, nice..i didnt think that way, cos i have not switched more than one variable before @Blauelf @sjames1958gm
thanks @Blauelf @sjames1958gm
CamperBot
@camperbot
May 29 2017 08:55
kelechichinaka sends brownie points to @blauelf and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 4261 | @blauelf |http://www.freecodecamp.com/blauelf
:star2: 7529 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Blauelf
@Blauelf
May 29 2017 08:55
@kelechichinaka It's not what switch is built for, in my opinion. But it's using language features in a way they can be used.
Javier Pons
@JavierPons
May 29 2017 08:56
@sjames1958gm can you spell it : sentence.slice(-p.length) !== p)? sentence (-p.length = the last word of string?
its different to string?
Stephen James
@sjames1958gm
May 29 2017 08:57
@JavierPons From MDN slice:
A negative index can be used, indicating an offset from the end of the sequence. slice(-2) extracts the last two elements in the sequence.
so -p.length grabs the end of sentence of p length
Blauelf
@Blauelf
May 29 2017 08:57
@kelechichinaka There are more ways, like return a + [" is smaller than ", " is equal to ", " is greater than "][1 + (a > b) - (b > a)] + b; and many more.
Javier Pons
@JavierPons
May 29 2017 08:58
@sjames1958gm yes, but I can't understand yet !==p its not p??
Saif Ur Rahman
@saifsmailbox98
May 29 2017 08:58
look at this
Kelechi Chinaka
@ke1echi
May 29 2017 08:58
hmm.. always learning from u guys :+1: @Blauelf @sjames1958gm
Stephen James
@sjames1958gm
May 29 2017 08:58
@JavierPons yes. That is true if the sentence does not end with "please?"
Blauelf
@Blauelf
May 29 2017 08:59
@kelechichinaka Javascript has inherited from C an infinite number of ways for solving problems. Which makes some code pretty unreadable.
Nasridean
@Nasridean
May 29 2017 09:00

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

  if (ch !== -1) {
    return true;
  }
}

mutation(["hello", "Hello"]);
what's wrong with this code?
Markus Kiili
@Masd925
May 29 2017 09:00
@Nasridean Initialize i.
aceroAD
@aceroAD
May 29 2017 09:01

now it tells me that i can have an infinite loop

function bouncer(arr) {

  var cont = [];

  for (var i = 0; i < arr.length ; i++){
    if (arr[i] === 0 || arr[i] === false || arr[i] === null || arr[i] === undefined || arr[i] === "" || arr[i] !== arr[i]) {

      cont = arr.splice(i,1);
      arr = cont;
      i -= 1;
    }
}
  return arr;
}

@Blauelf i dont know what happens, how you could do it with filter?

Stephen James
@sjames1958gm
May 29 2017 09:02
@aceroAD Well splice returns the deleted values - try removing the arr = cont
Nasridean
@Nasridean
May 29 2017 09:02
@Masd925 it' still not working
function mutation(arr) {
var ch = "";
   for (var i = 0; i <= arr[0].length; i++) {
   ch = arr[0].charAt[i].indexOf(arr[1].charAt[i]);
  }
      if (arr[0].indexOf(arr[1]) === -1) {
    return false;
  }

  if (ch !== -1) {
    return true;
  }
}

mutation(["hello", "Hello"]);
Stephen James
@sjames1958gm
May 29 2017 09:03
@Nasridean charAt is a function use () not []
Blauelf
@Blauelf
May 29 2017 09:03
@Nasridean You should initialise i. You should loop only to <, not <=, and use arr[1], not arr[0] for the loop index. Also, charAt is a function, requires parentheses () when being called, not square brackets []. The indexOfs are both wrong, as you should search in the whole first string for the ith character of the second string. The first if should probably be within the loop then.
Stephen James
@sjames1958gm
May 29 2017 09:03
@Nasridean Not sure why you are using charAt on arr[0]
You should toLowerCase both strings before the loop
@Nasridean This code adding [i] to [1] should be inside the loop
      if (arr[0].indexOf(arr[1][i]) === -1) {
    return false;
  }
aceroAD
@aceroAD
May 29 2017 09:05
@sjames1958gm thank you! i thought splice returned the arr without the elementes it takes.
CamperBot
@camperbot
May 29 2017 09:05
aceroad sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7530 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Timothy Bui
@timothyqbui
May 29 2017 09:05
how do you post the script in a black box like that to here?
Stephen James
@sjames1958gm
May 29 2017 09:05
@aceroAD :+1:
Alexandre Conrady
@Aberoom
May 29 2017 09:06
@timothyqbui three backticks on top and three on the bottom
@timothyqbui backticks (on a US keyboard) are under the esc key, left of the 1 key.
Blauelf
@Blauelf
May 29 2017 09:07
@sjames1958gm You mean arr[1][i], right?
Kelechi Chinaka
@ke1echi
May 29 2017 09:07
python tutor is not working, anyone tried that
Stephen James
@sjames1958gm
May 29 2017 09:07
@Blauelf oh, yeah
Timothy Bui
@timothyqbui
May 29 2017 09:07

```
var count = 0;
function cc(card) {
// Only change code below this line

switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
count = count + 1;
break;
case 7:
case 8:
case 9:
count = count + 0;
break;
case 10:
case "J":
case "Q":
case "K":
case "A":
count = count - 1;
}

switch (count) {
case count > 0:
count = count + " Bet";
break;
case count <= 0:
count = count + " Hold";
}
return count;
// Only change code above this line
}

// Add/remove calls to test your function.

// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

readyForReal
@readyForReal
May 29 2017 09:08
Hey guys, can someone check my code on the "Title Case a Sentence", I met all the criteria, but itstill wont let me go through
Timothy Bui
@timothyqbui
May 29 2017 09:08
damn....
Kelechi Chinaka
@ke1echi
May 29 2017 09:08
any other tool to visualize code
Timothy Bui
@timothyqbui
May 29 2017 09:08

```js
var count = 0;
function cc(card) {
// Only change code below this line

switch (card) {
case 2:
case 3:
case 4:
case 5:
case 6:
count = count + 1;
break;
case 7:
case 8:
case 9:
count = count + 0;
break;
case 10:
case "J":
case "Q":
case "K":
case "A":
count = count - 1;
}

switch (count) {
case count > 0:
count = count + " Bet";
break;
case count <= 0:
count = count + " Hold";
}
return count;
// Only change code above this line
}

// Add/remove calls to test your function.

// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');

Markus Kiili
@Masd925
May 29 2017 09:08
@timothyqbui Use if to test count.
Stephen James
@sjames1958gm
May 29 2017 09:08
@timothyqbui Use an if not a switch for the second part
Timothy Bui
@timothyqbui
May 29 2017 09:08
sorry about spam...cant do it
Blauelf
@Blauelf
May 29 2017 09:09
@timothyqbui Do not switch for the second part, but use if, or the conditional/ternary operator ? :, which is like if-else as an expression.
Timothy Bui
@timothyqbui
May 29 2017 09:09
okie thanks
Stephen James
@sjames1958gm
May 29 2017 09:09
@timothyqbui You need three ``` at the end on their own line -
You can edit your most recent post with up arrow
Blauelf
@Blauelf
May 29 2017 09:09
Or click triple dots on the upper right of a post you hover over (also allows for quoting or deleting posts)
Timothy Bui
@timothyqbui
May 29 2017 09:10
ok ty
Blauelf
@Blauelf
May 29 2017 09:11
To inert a line break in chat mode, you can use Shift+Return
readyForReal
@readyForReal
May 29 2017 09:11

``` var arr = [];
function titleCase(str) {
var split = str.toLowerCase().split(" "); // to lowerCase and split by words
for (var i = 0; i < split.length; i++) { // iterate over every element
var x = split[i].split(""); // split by letters
var z = x[0].toUpperCase(); // capitalize first letter
x.shift(); // remove first letter in array
x.unshift(z); // add capitalized letter
var a = x.join(""); // create a string of array letters
arr.push(a); // push that string into out array
}
str = arr.join(" "); // glue it all back
return str;
}

titleCase("I'm a little tea pot");
```

AminaKhan13
@AminaKhan13
May 29 2017 09:11

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

}
}
return arr;
} Hey guys, I have to return an array consisting of the largest number from each provided sub-array. I don't know whats wrong !

Markus Kiili
@Masd925
May 29 2017 09:12
@AminaKhan13 You need two loops or iterations.
Stephen James
@sjames1958gm
May 29 2017 09:12
@Blauelf You need to move arr inside the function -
AminaKhan13
@AminaKhan13
May 29 2017 09:12
@readyForReal hey, instead of doing all that unshift and shift, use charAt for the first letter, and splice off the remaining word
Blauelf
@Blauelf
May 29 2017 09:13
@sjames1958gm Name autocomplete is evil :P
readyForReal
@readyForReal
May 29 2017 09:13
how do I post code here ? not as text
AminaKhan13
@AminaKhan13
May 29 2017 09:13
@Masd925 ohh ... okay
Stephen James
@sjames1958gm
May 29 2017 09:13
@Blauelf Oops, or just bad clicking
Stephen James
@sjames1958gm
May 29 2017 09:13
@readyForReal Move arr inside the function-
Nasridean
@Nasridean
May 29 2017 09:14

@Blauelf @sjames1958gm I made as you told


function mutation(arr) {
var ch = "";
var arr0 = arr[0].toLowerCase();
var arr1 = arr[1].toLowerCase();
   for (var i = 0; i <= arr1.length; i++) {
   ch = arr0.indexOf(arr1.charAt(i));
     if (arr0.indexOf(arr1) === -1) {
       return false;
  }
   }

  if (ch !== -1) {
    return true;
  }
}

mutation(["hello", "Hello"]);

still not working

readyForReal
@readyForReal
May 29 2017 09:14
```
Blauelf
@Blauelf
May 29 2017 09:14
@Nasridean Use <, not <=
Javier Pons
@JavierPons
May 29 2017 09:14
sentence.slice(-p.length) !== p)? @sjames1958gm thanks Now I start to got it. Im making exercises in the console!
CamperBot
@camperbot
May 29 2017 09:14
javierpons sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7531 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Nasridean
@Nasridean
May 29 2017 09:14
@Blauelf used still the same
Timothy Bui
@timothyqbui
May 29 2017 09:14
@Masd925 @sjames1958gm @Blauelf thanks guys :)( worked perfect :)
CamperBot
@camperbot
May 29 2017 09:14
timothyqbui sends brownie points to @masd925 and @sjames1958gm and @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4262 | @blauelf |http://www.freecodecamp.com/blauelf
:star2: 4156 | @masd925 |http://www.freecodecamp.com/masd925
:star2: 7532 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Kelechi Chinaka
@ke1echi
May 29 2017 09:15
any tool to visualize code @Blauelf @sjames1958gm
Blauelf
@Blauelf
May 29 2017 09:15
@Nasridean Also, you need only one indexOf. The first one looks promising. Should be in the place of the second. And you don't need that ch at all.
Stephen James
@sjames1958gm
May 29 2017 09:15
@Nasridean You don't need ch - if your loop ends then just return true - also indexOf(arr1[i])
readyForReal
@readyForReal
May 29 2017 09:15
code goes here ?
Stephen James
@sjames1958gm
May 29 2017 09:15
@kelechichinaka You can always just console.log and something like repl.it or jsbin
readyForReal
@readyForReal
May 29 2017 09:16
@Blauelf thanks
now back to my code, its fully working but something is wrong, doesnt go trough, thought ? ```
CamperBot
@camperbot
May 29 2017 09:16
readyforreal sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4263 | @blauelf |http://www.freecodecamp.com/blauelf
readyForReal
@readyForReal
May 29 2017 09:16
var arr = [];
function titleCase(str) {
  var split = str.toLowerCase().split(" "); // to lowerCase and split by words
  for (var i = 0; i < split.length; i++) { // iterate over every element
    var x = split[i].split(""); // split by letters
    var z = x[0].toUpperCase(); // capitalize first letter
    x.shift(); // remove first letter in array
    x.unshift(z); // add capitalized letter
    var a = x.join(""); // create a string of array letters
    arr.push(a); // push that string into out array
  }
  str = arr.join(" "); // glue it all back
  return str;
}

titleCase("I'm a little tea pot");
Blauelf
@Blauelf
May 29 2017 09:16
@readyForReal :point_up: 29. Mai 2017 11:13
Kelechi Chinaka
@ke1echi
May 29 2017 09:17
i dont know y python tutor stopped working @sjames1958gm
Markus Kiili
@Masd925
May 29 2017 09:17
@readyForReal Global variable like that can mess up FCC tests.
Blauelf
@Blauelf
May 29 2017 09:18
@readyForReal Global variable won't reset between function calls, so first call might work, but second and after will fail
Sylvain
@orphen92
May 29 2017 09:20
Hi all it is possible to add a .shift directly before a .push like arr.push().shift()?
AminaKhan13
@AminaKhan13
May 29 2017 09:20
function largestOfFour(arr) {
// You can do this!
var temp = 0;
for(var i = 0; i < arr.length; i++){
for(var j = 1; j < arr.length; j++){
if(arr[i] > arr[j]){
temp += arr[i];
}
else {
temp += arr[j];
}
}
return arr;
}
} I have to make an array of the largest numbers, please help !
readyForReal
@readyForReal
May 29 2017 09:20
thanks guys, going to try to find a duffrent solution, I guess they check it like :
```
titleCase("x");
titleCase("y");
titleCase("z");
Nasridean
@Nasridean
May 29 2017 09:20
@Blauelf @sjames1958gm I made as you told -- Finally, worked. Thank you very much!
CamperBot
@camperbot
May 29 2017 09:20
nasridean sends brownie points to @blauelf and @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7533 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
:star2: 4264 | @blauelf |http://www.freecodecamp.com/blauelf
Markus Kiili
@Masd925
May 29 2017 09:20
@AminaKhan13 j loop should loop over arr[i] indices.
Stephen James
@sjames1958gm
May 29 2017 09:21
@orphen92 No, because push returns the new length, not the array
readyForReal
@readyForReal
May 29 2017 09:21
@Blauelf @Masd925 thanks, just put globalvariable in the function for that reset effect, all good now !
CamperBot
@camperbot
May 29 2017 09:21
readyforreal sends brownie points to @blauelf and @masd925 :sparkles: :thumbsup: :sparkles:
:warning: readyforreal already gave blauelf points
:star2: 4157 | @masd925 |http://www.freecodecamp.com/masd925
Mercy Tum
@mercytum
May 29 2017 09:21
Hi, I'm having trouble with my 'counting cards' code:

var count = 0;

function cc(card) {
// Only change code below this line
switch(card){
case 2:
case 3:
case 5:
case 6:
count += 1;
break;
case 7:
case 8:
case 9:
count += 0;
break;
case 10:
case 'J':
case 'Q':
case 'K':
case 'A':
count -= 1;
break;
}

if (count > 0){
return count + " Bet";
} else {
return count + " Hold";
}

AminaKhan13
@AminaKhan13
May 29 2017 09:21
@Masd925 Didn't get ya
Mercy Tum
@mercytum
May 29 2017 09:21
Could someone please help
Blauelf
@Blauelf
May 29 2017 09:21
@mercytum What about case 4:?
Stephen James
@sjames1958gm
May 29 2017 09:21
@mercytum card 4 seems to be missing
Mercy Tum
@mercytum
May 29 2017 09:21
ow
Thanks, let me try that
Markus Kiili
@Masd925
May 29 2017 09:22
@AminaKhan13 Your second loop needs to loop over the subarray arr[i]
Sylvain
@orphen92
May 29 2017 09:22
@sjames1958gm ahh okay thank you i know now what is work with .filter :)
CamperBot
@camperbot
May 29 2017 09:22
orphen92 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 7534 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
AminaKhan13
@AminaKhan13
May 29 2017 09:22
ohh
Saif Ur Rahman
@saifsmailbox98
May 29 2017 09:22
why fa-thermometer-empty icon is not loading in my project while other icons like fa-apple are loading?
readyForReal
@readyForReal
May 29 2017 09:22
@sjames1958gm didnt see your message, figured it out the same way )
AminaKhan13
@AminaKhan13
May 29 2017 09:22
@Masd925 ill try that
Mercy Tum
@mercytum
May 29 2017 09:22
It's all good now, thanks guys!
Stephen James
@sjames1958gm
May 29 2017 09:25
@mercytum :+1:
Ogundele Olumide
@Lumexralph
May 29 2017 09:27
@sjames1958gm You guys surprised me on Saturday :smirk:
Stephen James
@sjames1958gm
May 29 2017 09:27
@Lumexralph Yeah, they played very poorly
Ogundele Olumide
@Lumexralph
May 29 2017 09:28
@sjames1958gm should that be anything to worry about?
George Kech.
@georgemitnick
May 29 2017 09:42
Hey, guys. I'm trying to make a quote and its author to load when the page is loading. What am I doing wrong?:
$(document).ready(fuction() {
  $.ajax( {
    url: "https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1",
    function(data) {
      var post = data.shift(); // The data is an array of posts. Grab the first one.
        $('#quote-title').text(post.title);
        $('#quote-content').html(post.content);
  });
});
Vikrant Singh
@VikrantSingh13
May 29 2017 09:43
@georgemitnick what result are you getting from this code? and what result were you expecting?
George Kech.
@georgemitnick
May 29 2017 09:43
When I run it on a browser it says unexpected ending and that something is missing
Vikrant Singh
@VikrantSingh13
May 29 2017 09:44
can you copy paste the error for us?
George Kech.
@georgemitnick
May 29 2017 09:44
I want that to be a part of the code that loads the quote when the page loads and another part where when I click on the button to give me a different quote.
Ani
@bluffmast3r
May 29 2017 09:44
Hi Guys, I am stuck at tutorial #158 - World Blanks. Sadly I am unable to understand this challenge. Can anyone help simplyfy this for me ? please
George Kech.
@georgemitnick
May 29 2017 09:44
@VikrantSingh13 One sec.
Vikrant Singh
@VikrantSingh13
May 29 2017 09:44
or give the codepen url
brb
Saif Ur Rahman
@saifsmailbox98
May 29 2017 09:45
I can see a different icon or background image (e.g. snowy mountain, hot desert) depending on the weather. how to complete this?
George Kech.
@georgemitnick
May 29 2017 09:45
@VikrantSingh13 "SyntaxError: missing ) after argument list [Learn More]"
Blauelf
@Blauelf
May 29 2017 09:46
@bluffmast3r Return a string which includes all the words passed in the four parameters. You could build that string by using string concatenation operator + to combine the four variables and at least three of your own string literals. The words (which are passed without spaces around) need to be separated by non-word characters in the final string.
Vikrant Singh
@VikrantSingh13
May 29 2017 09:47
@georgemitnick do you have the codepen url? so I can run it and see whats going on?
or are you using something else?
George Kech.
@georgemitnick
May 29 2017 09:49
@VikrantSingh13 let me finish and the second function and I'll post you the codepen
give me few minutes
Ani
@bluffmast3r
May 29 2017 09:49
@Blauelf cool. I'll give that a go. I read the instructions in the tutorial but they just looked like words without any meaning. Or maybe my brain is saturated for the night. cheers dude
Vikrant Singh
@VikrantSingh13
May 29 2017 09:50
okie
Blauelf
@Blauelf
May 29 2017 09:51
@georgemitnick This code looks like a mashup of ajax(url, success) and ajax({url:"", success:function(data){}}) (decide on one, and get it right)
George Kech.
@georgemitnick
May 29 2017 09:52
@Blauelf You're right. I'm trying to copy a frame work that uses $getJSON and combine it with ajax call
Vikrant Singh
@VikrantSingh13
May 29 2017 09:52
rip
Blauelf
@Blauelf
May 29 2017 09:55
@georgemitnick Just realized that ajax has no such thing as ajax(url, success). So adding a success: and a } might fix that code, like
$(document).ready(fuction() {
  $.ajax( {
    url: "https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1",
    success: function(data) { // added success
      var post = data.shift(); // The data is an array of posts. Grab the first one.
      $('#quote-title').text(post.title);
      $('#quote-content').html(post.content);
    } // closing function
  });
});
(unless of course CORS issues prevent this from working)
George Kech.
@georgemitnick
May 29 2017 09:56
@Blauelf Let me try
George Kech.
@georgemitnick
May 29 2017 10:02
@Blauelf Doesn't seem to make any difference. The page should have load the quote at least. Unless if there's some other error.
Blauelf
@Blauelf
May 29 2017 10:02
@georgemitnick Have you checked the error messages on the browser console?
George Kech.
@georgemitnick
May 29 2017 10:03
@Blauelf Nah. I'm going to do it now.
Blauelf
@Blauelf
May 29 2017 10:03
Found a typo fuction :P
George Kech.
@georgemitnick
May 29 2017 10:04
hmm let me check
it has the first function too hah
Blauelf
@Blauelf
May 29 2017 10:05
Had to fix success+}, now the code is at least without !
George Kech.
@georgemitnick
May 29 2017 10:06
@Blauelf Still gives the same error. Sound I add success?
Blauelf
@Blauelf
May 29 2017 10:07
$.ajax({
  url: "something",
  success: function(data) {
    ...
  }
});
George Kech.
@georgemitnick
May 29 2017 10:07
Yep
Let me add it.
Blauelf
@Blauelf
May 29 2017 10:08
Shows quotes for me after adding success: twice and missing } once
Vikrant Singh
@VikrantSingh13
May 29 2017 10:10
yeah you had missing }, function typo
Mohammed Boudad
@matrixersp
May 29 2017 10:10
A better solution for this? (Caesars Cipher)
function rot13(str) { // LBH QVQ VG!
  var str2 = "";
  for(var i = 0; i < str.length; i++) {
    if(str.charCodeAt(i) < 78 &&  str.charCodeAt(i) >= 65)
      str2 += String.fromCharCode(str.charCodeAt(i)+13);
    else if(str.charCodeAt(i) < 65)
      str2 += str[i];
    else
      str2 += String.fromCharCode(str.charCodeAt(i)-13);
  }
  console.log(str2);
  return str2;
}
rot13("SERR PBQR PNZC");
Markus Kiili
@Masd925
May 29 2017 10:12
@Tekkie7 You could use map method and do the charcode transformation with one remainder operation (not sure if it is any clearer that +-13 way).
Mohammed Boudad
@matrixersp
May 29 2017 10:12
@Masd925 map is for arrays no?
Vikrant Singh
@VikrantSingh13
May 29 2017 10:12
@georgemitnick the new quote button is not working however you may wanna look into it
Markus Kiili
@Masd925
May 29 2017 10:13
@Tekkie7 Yes, but you can find ways to use map here. String replace is another option.
George Kech.
@georgemitnick
May 29 2017 10:13
@VikrantSingh13 I copied your code and it still doesn't load the quote with the page load. What's wrong with the button section?
Vikrant Singh
@VikrantSingh13
May 29 2017 10:13
@Tekkie7 you can split the str into array and use map and then join it back
Mohammed Boudad
@matrixersp
May 29 2017 10:13
@Masd925 Okay, thanks
CamperBot
@camperbot
May 29 2017 10:13
tekkie7 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4158 | @masd925 |http://www.freecodecamp.com/masd925
Vikrant Singh
@VikrantSingh13
May 29 2017 10:14
@georgemitnick check the link I posted its working for me
George Kech.
@georgemitnick
May 29 2017 10:14
@VikrantSingh13 and codepen gives me an error "Unexpected token )"
George Kech.
@georgemitnick
May 29 2017 10:14
@VikrantSingh13 I copied the code of your link and it doesn't work on my page
Markus Kiili
@Masd925
May 29 2017 10:14
@Tekkie7 Maybe the most clear way I can think is something like this:
function rot13(str) {
  var Acode = "A".charCodeAt(0);
  var Zcode = "Z".charCodeAt(0);
  var NUMLETTERS = Zcode-Acode+1;
  return str.split("").map(function(char){
    var cc = char.charCodeAt(0);
    if (cc>=Acode && cc<=Zcode) {
      cc += 13;
      if (cc>Zcode) cc-=NUMLETTERS;
    }
    return String.fromCharCode(cc);
  }).join("");
}
Vikrant Singh
@VikrantSingh13
May 29 2017 10:15
@georgemitnick you copied the code wrong do it again lol
George Kech.
@georgemitnick
May 29 2017 10:16
@VikrantSingh13 Now it works. But why isn't the button working? What did I do wrong?
Vikrant Singh
@VikrantSingh13
May 29 2017 10:16
looking into it
alpox
@alpox
May 29 2017 10:18
@Tekkie7 A bit a more complicated one as from @Masd925:
function rot13(str) {
  return str.split('').map(function(sub) {
    if(!/[A-Z]/.exec(sub)) return sub;
    var ch = sub.charCodeAt(0);
    ch += 13;
    if(ch > 90) ch -= 26;
    return String.fromCharCode(ch);
  }).join('');
}
freecodecampo
@freecodecampo
May 29 2017 10:19
Hi Guys im trying to get this api to work what am i doing wrong ?
https://codepen.io/anon/pen/XRwGxx
alpox
@alpox
May 29 2017 10:21
@freecodecampo You gotta choose another weather api than openweathermap. It will not work anymore with that one
Victor Popescu
@VicPopescu
May 29 2017 10:22
@alpox Uncaught ReferenceError: $ is not defined try to read your console
alpox
@alpox
May 29 2017 10:22
@VicPopescu Got the wrong guy? :D
Stephen James
@sjames1958gm
May 29 2017 10:22
@freecodecampo codepen is now https only and openweather is http only so you cannot use openweather directly from
codepen (cannot access unsecure http from https).
Victor Popescu
@VicPopescu
May 29 2017 10:22
@alpox then jquery.min.js:4 Mixed Content: The page at 'https://codepen.io/anon/pen/XRwGxx' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://api.openweathermap.org/data/2.5/weather?q=London&appid=191f19189c672c5129fb72335d2162bb&units=metric'. This request has been blocked; the content must be served over HTTPS.
@alpox ah sry :))
alpox
@alpox
May 29 2017 10:24
@VicPopescu Now i got confused too Ugh :D
Victor Popescu
@VicPopescu
May 29 2017 10:24
@alpox i clicked when you typed and selected you
alpox
@alpox
May 29 2017 10:24
Yea np :D
Victor Popescu
@VicPopescu
May 29 2017 10:24
@freecodecampo use darksky API because it is supporting https and use crossorigin.me for CORS pass
freecodecampo
@freecodecampo
May 29 2017 10:25
@VicPopescu thanks
CamperBot
@camperbot
May 29 2017 10:25
freecodecampo sends brownie points to @vicpopescu :sparkles: :thumbsup: :sparkles:
:cookie: 461 | @vicpopescu |http://www.freecodecamp.com/vicpopescu
freecodecampo
@freecodecampo
May 29 2017 10:25
@sjames1958gm thanks
Victor Popescu
@VicPopescu
May 29 2017 10:25
@freecodecampo here are the links https://darksky.net/dev/ and https://crossorigin.me/
Vikrant Singh
@VikrantSingh13
May 29 2017 10:26
@georgemitnick i believe you have to set the ajax cache to false or the quotes won't update
George Kech.
@georgemitnick
May 29 2017 10:26
@VikrantSingh13 you might be right. do you wanna see the original code?
Vikrant Singh
@VikrantSingh13
May 29 2017 10:27
okay
George Kech.
@georgemitnick
May 29 2017 10:27
@VikrantSingh13 It was working only by clicking the button:
$('#get-another-quote-button').on('click', function(e) {
    e.preventDefault();
    $.ajax( {
      url: 'https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1',
      success: function(data) {
        var post = data.shift(); // The data is an array of posts. Grab the first one.
        $('#quote-title').text(post.title);
        $('#quote-content').html(post.content);

        // If the Source is available, use it. Otherwise hide it.
        if (typeof post.custom_meta !== 'undefined' && typeof post.custom_meta.Source !== 'undefined') {
          $('#quote-source').html('Source:' + post.custom_meta.Source);
        } else {
          $('#quote-source').text('');
        }
      },
      cache: false
    });
  });
@georgemitnick Do you think that the "if" part should be added too?
Vikrant Singh
@VikrantSingh13
May 29 2017 10:29
@georgemitnick the if part is just a try/catch, it has nothing to do with the cache
George Kech.
@georgemitnick
May 29 2017 10:30
@VikrantSingh13 I thought so.
@VikrantSingh13 Where can I add the cache: false?
Vikrant Singh
@VikrantSingh13
May 29 2017 10:32
just like it shows in the code
Nasridean
@Nasridean
May 29 2017 10:33
What's wrong with this code?

function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  function nonFalsy(val) {
    return val !== false,null, 0,"",undefined,NaN;
  }
  return arr.filter(nonFalsy);
}

bouncer([7, "ate", "", false, 9]);
George Kech.
@georgemitnick
May 29 2017 10:33
Doesn't work
Dawid Nazarko
@quarhodron
May 29 2017 10:33
hello, I have problem
Markus Kiili
@Masd925
May 29 2017 10:33
@Nasridean You are using the comma operator there by accident.
Ogundele Olumide
@Lumexralph
May 29 2017 10:34
@Nasridean you need to separate the comparisons
Markus Kiili
@Masd925
May 29 2017 10:34
@Nasridean Needs to be return val!==false && val!==null &&...
Ogundele Olumide
@Lumexralph
May 29 2017 10:34
@Masd925 Good Morning
@quarhodron ask
Vikrant Singh
@VikrantSingh13
May 29 2017 10:34
Markus Kiili
@Masd925
May 29 2017 10:34
@Lumexralph Morning. I finally started my clear code gist on FCC challenges.
Vikrant Singh
@VikrantSingh13
May 29 2017 10:35
write a default predefined quote in the html and let the user use the generate quote button and it will work fine @georgemitnick
George Kech.
@georgemitnick
May 29 2017 10:35
@VikrantSingh13 Yeah, but it doesn't have a quote already loaded before you click
@VikrantSingh13 My goal is to have a quote written already before I click on the button
@VikrantSingh13 Oh I see what you mean
@VikrantSingh13 I thought it would be better if I did it with a function
Nasridean
@Nasridean
May 29 2017 10:37
still not working

function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  function nonFalsy(val) {
    return val !== false && val !== null && val !== 0 && val !== "" && val !== undefined && val !== isNaN;
  }
  return arr.filter(nonFalsy);
}

bouncer([7, "ate", "", false, 9]);
Markus Kiili
@Masd925
May 29 2017 10:37
@Nasridean NaN is funfunfun ;)
George Kech.
@georgemitnick
May 29 2017 10:37
@VikrantSingh13 The way you did it is basically the same as the original...
Ogundele Olumide
@Lumexralph
May 29 2017 10:38
@Masd925 way to go Bro!
Markus Kiili
@Masd925
May 29 2017 10:38
@Nasridean isNaN is not a test for value NaN. You could use val===val to test for not being NaN.
Ogundele Olumide
@Lumexralph
May 29 2017 10:38
@Nasridean NaN is not equal to anything so val === val // false
@Nasridean or use Number.isNaN(val)
Vikrant Singh
@VikrantSingh13
May 29 2017 10:39
@georgemitnick here's my own quote generator when I did the project if you want something for reference https://codepen.io/vikrantsingh13/pen/RRjJpV?editors=1010
Ogundele Olumide
@Lumexralph
May 29 2017 10:39
@Masd925 you have a link?
@Masd925 how can I start if I want to?
Markus Kiili
@Masd925
May 29 2017 10:40
@Lumexralph Start what?
https://gist.github.com/Masd925
Ogundele Olumide
@Lumexralph
May 29 2017 10:40

@Lumexralph Morning. I finally started my clear code gist on FCC challenges.

@Masd925 this

Nasridean
@Nasridean
May 29 2017 10:40
@Masd925 @Lumexralph it worked. Thank you very much!
CamperBot
@camperbot
May 29 2017 10:40
nasridean sends brownie points to @masd925 and @lumexralph :sparkles: :thumbsup: :sparkles:
:star2: 4159 | @masd925 |http://www.freecodecamp.com/masd925
:star2: 1831 | @lumexralph |http://www.freecodecamp.com/lumexralph
Ogundele Olumide
@Lumexralph
May 29 2017 10:43
@Masd925 cool
Markus Kiili
@Masd925
May 29 2017 10:48
@Lumexralph Dilutes the awfulness of those one-liners .
Devansh Trivedi
@D3V4N5H
May 29 2017 10:50
someone please help me with Mutation !!
Michał Gacka
@m3h0w
May 29 2017 10:50
Hey guys! I just started the bonfire algorithm challanges. Is there a way to use the console to debug while coding?
Devansh Trivedi
@D3V4N5H
May 29 2017 10:50
i'm stuck here

```function mutation(arr) {
var a=arr[0].toLowerCase;
var b=arr[1].toLowerCase;

var f=0,i=0,x=0,y=0;
while(f>-1){
f=b.indexOf(a[i]);i++;
}
if(f<0)x=1;

i=0;f=0;
while(f>-1){
f=a.indexOf(b[i]);i++;
}
if(f<0)y=1;

if(x==1||y==1) return true;
else return false;
}
mutation(["hello", "hey"]);```

Michał Gacka
@m3h0w
May 29 2017 10:50
console.log doesn't really output anything to the small black window on the left
Devansh Trivedi
@D3V4N5H
May 29 2017 10:51

`function mutation(arr) {
var a=arr[0].toLowerCase;
var b=arr[1].toLowerCase;

var f=0,i=0,x=0,y=0;
while(f>-1){
f=b.indexOf(a[i]);i++;
}
if(f<0)x=1;

i=0;f=0;
while(f>-1){
f=a.indexOf(b[i]);i++;
}
if(f<0)y=1;

if(x==1||y==1) return true;
else return false;
}
mutation(["hello", "hey"]);`

Ogundele Olumide
@Lumexralph
May 29 2017 10:51
@m3h0w you can use your browser console, or Node on CMD or use https://repl.it/languages/JavaScript
MadsSN
@MadsSN
May 29 2017 10:51
Can someone provide some help with Intermediate Algorithm's Arguments optional?
Ogundele Olumide
@Lumexralph
May 29 2017 10:52
@Masd925 yeah, for production.... why do we even bother about one liner?
Michał Gacka
@m3h0w
May 29 2017 10:52
@Lumexralph thanks. I hoped maybe there is a way to use that black box on the left.
Markus Kiili
@Masd925
May 29 2017 10:52
@Lumexralph It is a sport somewhat related to programming. Can teach something useful at best.
CamperBot
@camperbot
May 29 2017 10:52
:star2: 1832 | @lumexralph |http://www.freecodecamp.com/lumexralph
m3h0w sends brownie points to @lumexralph :sparkles: :thumbsup: :sparkles:
Frostbites
@Frostbites
May 29 2017 10:53
Hey Folks
I am stuck here on the drill "Stand in Line"
Ogundele Olumide
@Lumexralph
May 29 2017 10:53
@Masd925 kind of agree with that sport
Frostbites
@Frostbites
May 29 2017 10:53

function nextInLine(arr, item) {
// Your code here

var a = arr.shift(); // Change this line
arr.push(item);
return arr, a;

}

Ogundele Olumide
@Lumexralph
May 29 2017 10:54
@Frostbites you have to push before shift
Frostbites
@Frostbites
May 29 2017 10:54
Aha, but why ?
It worked.
Ogundele Olumide
@Lumexralph
May 29 2017 10:55
@Frostbites if you have an empty array
Markus Kiili
@Masd925
May 29 2017 10:55
@Lumexralph Code at best is like a poem that effortlessly flows into the brain without conscious processing.
Ogundele Olumide
@Lumexralph
May 29 2017 10:57
@Masd925 yeah.....flows moving in the head
Ashish Patel
@ashishpatelcs
May 29 2017 10:58
Hello everyone, What are we talking about poems?
Dan Couper
@DanCouper
May 29 2017 11:00
@D3V4N5H there are tools like uglify that will reformat code written so that people can understand it with code only a computer can understand, you don't need to do that job in advance
The code you've written is almost impossible to understand because you've used meaningless single letter variables throughout the entire thing
Ogundele Olumide
@Lumexralph