6th
May 2016
Norvin Burrus
@ndburrus
May 06 2016 00:03
@shaunleow ...perhaps your multiplication is in the wrong position. hint: celsius get multiplied by the fraction... you are correct, fahrenheit is defined - don't worry about that.
Jonathan Mitchell
@Vanhealen
May 06 2016 00:04
yeahaw
Brendan Kinahan
@BKinahan
May 06 2016 00:04
hawyea
shaunleow
@shaunleow
May 06 2016 00:06

function convertToF(celsius) {
// Only change code below this line

var fahrenheit = celsius * 9/5 + 32;

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

// Change the inputs below to test your code
convertToF(30);

sorry dont know how to copy the code. newb
Brendan Kinahan
@BKinahan
May 06 2016 00:06
@shaunleow
```js
```
Clay Shaw
@itsClay
May 06 2016 00:06

I have a question regarding the "Profile Look up" problem:

I have a working solution here:
```js function lookUpProfile(firstName, prop){
// Only change code below this line
var i = 0;

while (i < contacts.length){
if(contacts[i].firstName == firstName && contacts[i].hasOwnProperty(prop)){
console.log('success!');
return contacts[i][prop];
} else if (contacts[i].firstName == firstName && contacts[i].hasOwnProperty(prop) !== prop) {
console.log("No such property");
return "No such property";
} else {
i++;
}
}
return "No such contact";

// Only change code above this line
}```

however I am wondering why this alternative solution won't work for ```js lookUpProfile("Bob", "number")

```function lookUpProfile(firstName, prop){
// Only change code below this line
var i = 0;
var currentFirstName = "";

while (i < contacts.length){
if(contacts[i].firstName == firstName && contacts[i].hasOwnProperty(prop)){
console.log('success!');
return contacts[i][prop];
} else if (contacts[i].firstName == firstName && contacts[i].hasOwnProperty(prop) !== prop) {
console.log("No such property");
return "No such property";
} else {
i++;
currentFirstName = contacts[i].firstName;
}
}
if (currentFirstName !== firstName) {
return "No such contact";
}

// Only change code above this line
}```

Norvin Burrus
@ndburrus
May 06 2016 00:06
@mathranger101 ...did you mean to use - ?
``return usedNums.push(cur);``
Clay Shaw
@itsClay
May 06 2016 00:07
ugh sry messed up MD
Brendan Kinahan
@BKinahan
May 06 2016 00:08
@shaunleow Your code works just fine for me; try refreshing the page.
shaunleow
@shaunleow
May 06 2016 00:08
refresh! omg. thanks everyone. sorry to bother u.
Clay Shaw
@itsClay
May 06 2016 00:09

I have a question regarding the "Profile Look up" problem:

I have a working solution here:

``````function lookUpProfile(firstName, prop){
// Only change code below this line
var i = 0;

while (i < contacts.length){
if(contacts[i].firstName == firstName && contacts[i].hasOwnProperty(prop)){
console.log('success!');
return contacts[i][prop];
} else if (contacts[i].firstName == firstName && contacts[i].hasOwnProperty(prop) !== prop) {
console.log("No such property");
return "No such property";
} else {
i++;
}
}
return "No such contact";

// Only change code above this line
}``````

however I am wondering why this alternative solution won't work for

``lookUpProfile("Bob", "number")``
``````function lookUpProfile(firstName, prop){
// Only change code below this line
var i = 0;
var currentFirstName = "";

while (i < contacts.length){
if(contacts[i].firstName == firstName && contacts[i].hasOwnProperty(prop)){
console.log('success!');
return contacts[i][prop];
} else if (contacts[i].firstName == firstName && contacts[i].hasOwnProperty(prop) !== prop) {
console.log("No such property");
return "No such property";
} else {
i++;
currentFirstName = contacts[i].firstName;
}
}
if (currentFirstName !== firstName) {
return "No such contact";
}

// Only change code above this line
}``````
Mike Moss
@MMux
May 06 2016 00:12
help roman numeral
CamperBot
@camperbot
May 06 2016 00:12

# Problem Explanation:

• You will create a program that converts an integer to a Roman Numeral.
:pencil: read more about algorithm roman numeral converter on the FCC Wiki
Norvin Burrus
@ndburrus
May 06 2016 00:13
@itsClay which test/s does/do not pass?
Clay Shaw
@itsClay
May 06 2016 00:13
``lookUpProfile("Bob", "number")``
Diego Mayer
@Chrono79
May 06 2016 00:15
@itsClay move the i++ below currentFirstName...
Clay Shaw
@itsClay
May 06 2016 00:15
omg it was that simple!
thanks! @Chrono79
CamperBot
@camperbot
May 06 2016 00:16
itsclay sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
Norvin Burrus
@ndburrus
May 06 2016 00:16
@Chrono79 ...good eye...:)
Clay Shaw
@itsClay
May 06 2016 00:16
very good catch
Norvin Burrus
@ndburrus
May 06 2016 00:19
help format @shaunleow
CamperBot
@camperbot
May 06 2016 00:19
no wiki entry for: `format @shaunleow`
Norvin Burrus
@ndburrus
May 06 2016 00:19
help format
CamperBot
@camperbot
May 06 2016 00:19

## :point_right: code formatting [wiki]

### Multi line Code

```js ⇦ Type 3 backticks and then press `[shift + enter ⏎]` (type js or html or css)

``````<paste your code here>,
then press [shift + enter ⏎]``````

``` ⇦ Type 3 backticks, then press `[enter ⏎]`

### Single line Code

This an inline ``<paste code here>`` code formatting with a single backtick(`) at start and end around the `code`.

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

Norvin Burrus
@ndburrus
May 06 2016 00:19
This message was deleted
CamperBot
@camperbot
May 06 2016 00:19
no wiki entry for: `paste code`
Shane Murphy
@ShaneMurphy91
May 06 2016 00:19
var myStr = "This is the start." + "This is the end.";
whats wrong with this?
myStr should have a value of This is the start. This is the end.
?
Diego Mayer
@Chrono79
May 06 2016 00:19
@ShaneMurphy91 a space missed?
Norvin Burrus
@ndburrus
May 06 2016 00:20
@ShaneMurphy91 - no space?
Shane Murphy
@ShaneMurphy91
May 06 2016 00:20
I spaced it out
Norvin Burrus
@ndburrus
May 06 2016 00:22
@ShaneMurphy91 it works...
``````var myStr = "This is the start." + "This is the end.";
console.log(myStr);
output:

This is the start.This is the end.``````
DJ Pelland
@dna113p
May 06 2016 00:27
``````\$('document').ready(function() {
\$('#search').on('submit', function() {
initSearch(\$('#search-input').val())
})
});

function initSearch(terms){
\$.ajax({
url: '//en.wikipedia.org/w/api.php',
data: {
action: 'query',
list: 'search',
srsearch: terms,
format: 'json'
},
dataType: 'jsonp',
success: function(x) {
displayResults(x.query.search);
}
});``````
Hello! I am having trouble getting this code working. The jquery ajax call works fine when I just run it on document ready, but once it is wrapped inside of the initSearch() function it will no longer run the sucess function... I can't figure out why
Angelo Ryndon
@AIRyndon
May 06 2016 00:30
``````function titleCase(str)
{
var newArray = str.split(" ");
var casedString = "";

function changeCase(val)
{
return val.toUpperCase();
}

for( var item in newArray)
{
casedString += newArray[item].toLowerCase().replace(/[a-z?]/,changeCase) + " ";
}
return casedString;
}

titleCase("I'm a little tea pot");``````
Halo Guys! I'm on the TitleCasing Bonfire. On the test thingy..this thing is returning fine...does it have to be type String when it returns? Thanks!
Greg Duncan
@GregatGit
May 06 2016 00:30
@nsloc22 @nsloc22 Thanks again pointing me in the map direction - it is very useful indeed
CamperBot
@camperbot
May 06 2016 00:30
gregatgit sends brownie points to @nsloc22 :sparkles: :thumbsup: :sparkles:
:warning: gregatgit already gave nsloc22 points
Angelo Ryndon
@AIRyndon
May 06 2016 00:30
I'm failing it and think that is what the editor wants
Diego Mayer
@Chrono79
May 06 2016 00:32
@AIRyndon you add an unneeded space at the end
Better use an array and join(" ") before returning
Like this:
``````...
for( var item in newArray)
{
newArray[item] = newArray[item].toLowerCase().replace(/[a-z?]/,changeCase);
}
return newArray.join(" ");
}``````
Nikhil
@nikhiltom
May 06 2016 00:39
This message was deleted
Angelo Ryndon
@AIRyndon
May 06 2016 00:42
@Chrono79 Thanks Bro! I was doing it so manually and forgot the join method..LOL
CamperBot
@camperbot
May 06 2016 00:42
airyndon sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
India
@indiamos
May 06 2016 00:45
Hellllllp! I'm on the “Find the Longest Word in a String” challenge, and although my code works in CodePen, the built-in tester says it's returning the wrong result on the input “May the force be with you.” Any idea why? http://codepen.io/indiamos/pen/mPeZJx/
Erik Villoria
@kire73
May 06 2016 00:45
help exact change
CamperBot
@camperbot
May 06 2016 00:45

# Problem Explanation:

• You have to create a program that will handle when the register does not have
enough cash or will have no cash after the transaction. Other than that it
needs to return an array of the change in the form of an array, so that will
be a 2D array.
Angelo Ryndon
@AIRyndon
May 06 2016 00:46

@indiamos ```

function findLongestWord(str) {
var newArray = str.split(' ');
var longest = 0;

for(var i in newArray)
{
var newLength = newArray[i].length;
longest = (newLength >= longest)?newLength:longest;
}

return longest;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
```

I did it like that @indiamos
Nikhil
@nikhiltom
May 06 2016 00:46

hello everyone, I have a question relating to 'falsy-bouncer' challenge. I wrote some code and before I wrote the if statement for callback function, I tested the code. It returned the correct answer. Now, I am wondering how that happened. Below is the code I wrote and I would really appreciate if someone can help me understand how filter function recognized what I didn't need inside my 'newArr'. Thank you.
<code>
function bouncer(arr) {
// Don't show a false ID to this bouncer.
var newArr=[];
//filter the array for this current element
newArr = arr.filter(bounceThis);
console.log(newArr);
return newArr;
}

function bounceThis(val){
return val;
}

bouncer([1, null, NaN, 2, undefined]); </code>

Moisés Man
@moigithub
May 06 2016 00:48
@indiamos move
var stringAsArray = [];
var winner = "";
inside ur funciton
Paweł Przytuła
@paprzytula
May 06 2016 00:48
what does the (uppercase) W do in regexp?
India
@indiamos
May 06 2016 00:49
@AIRyndon Thanks! That's really interesting to see. You're using some syntax I'd forgotten about, and some I've never seen before.
CamperBot
@camperbot
May 06 2016 00:49
indiamos sends brownie points to @airyndon :sparkles: :thumbsup: :sparkles:
Diego Mayer
@Chrono79
May 06 2016 00:49
@paprzytula negate \w so it's the same as [^a-zA-Z0-9_]
India
@indiamos
May 06 2016 00:50
@moigithub Thanks. Good point.
CamperBot
@camperbot
May 06 2016 00:50
indiamos sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 1079 | @moigithub |http://www.freecodecamp.com/moigithub
Nikhil
@nikhiltom
May 06 2016 00:51
@paprzytula it matches a non-alpha numeric character excluding "_"
India
@indiamos
May 06 2016 00:51
So now it passes the test, but I still can't figure out why it wasn't passing before. Why did only that test string fail?
Angelo Ryndon
@AIRyndon
May 06 2016 00:51
@indiamos NP :smile:
jdownhower
@jdownhower
May 06 2016 00:51
India
@indiamos
May 06 2016 00:52
And why did I get a different—correct—result in CodePen?
Paweł Przytuła
@paprzytula
May 06 2016 00:52
thank you
Emma Cooper
@199coopere
May 06 2016 00:53
hey in the record collection challenge what do the instructions mean when they say "update or set the value for the prop"
eduwin7
@eduwin7
May 06 2016 00:54
Diego Mayer
@Chrono79
May 06 2016 00:54
@199coopere use = to update or set the value
Paweł Przytuła
@paprzytula
May 06 2016 00:54
@199coopere i think that mean in general to .push
eduwin7
@eduwin7
May 06 2016 00:55
i am on Logical Order in If Else Statements
Emma Cooper
@199coopere
May 06 2016 00:55
which value? and what is the property these variables are confusing to me @Chrono79 @paprzytula
Lurk
@reformedRattlesnake
May 06 2016 00:56
@nikhiltom Filter uses your callback as a truth test on every item in an array. Your callback's test is just the item, so filter is evaluating that into a boolean. Truthy values become true and so get put in the new filtered array.
Diego Mayer
@Chrono79
May 06 2016 00:56
@199coopere look at your function definition
`function updateRecords(id, prop, value) {` <- that value
Aaron
@amfische
May 06 2016 00:56
@199coopere the value is the one that is passed into the function
@199coopere the wording is a little tricky but it's basically saying if that album doesn't have the property that is being passed then add it
Diego Mayer
@Chrono79
May 06 2016 00:59
eduwin7
@eduwin7
May 06 2016 00:59
function orderMyLogic(val) {
if (val < 3) {
return "Less than 10";
} else if (val <9) {
return "Less than 5";
} else {
return "Greater than or equal to 10";
}
}
function orderMyLogic(val) {
if (val < 4) {
return "Less than 10";
} else if (val <6) {
return "Less than 5";
} else {
return "Greater than or equal to 10";
}
}
need to get this one //orderMyLogic(6) should return "Less than 10"
Diego Mayer
@Chrono79
May 06 2016 01:00

@eduwin7 look at the text, and the conditions

``````if (val < 4) {
return "Less than 10";``````

they don't match
and you have to put them in a "logical" order

Islam Ibakaev
@dagman
May 06 2016 01:01
@eduwin7 i like this part :smile:
``````else if (val <6) {
return "Less than 5";``````
rphares
@rphares
May 06 2016 01:02
Once you make them match, yo'll want to put them in order--
for example, if i put 2 in what you have, what would happen? @eduwin7
Aaron
@amfische
May 06 2016 01:03
<h1>Testing</h1>
rphares
@rphares
May 06 2016 01:03
it would get to that first `if (val < 4)`
Nikhil
@nikhiltom
May 06 2016 01:03
That makes sense!
Thank you @reformedRattlesnake .
CamperBot
@camperbot
May 06 2016 01:03
nikhiltom sends brownie points to @reformedrattlesnake :sparkles: :thumbsup: :sparkles:
Aaron
@amfische
May 06 2016 01:03
`<h1>Testing</h1>`
rphares
@rphares
May 06 2016 01:03
which is true, so it would return `return "Less than 10";` @eduwin7
it would never get to `return "Less than 5";` because the first one was true, so it already `return`ed....
Aaron
@amfische
May 06 2016 01:04
`var code = "formatted";`
``var code = "formatted";``
Erik Villoria
@kire73
May 06 2016 01:11
So I've finished exact change but my numbers are all strings. I can't seem to be able to convert them without losing decimals.
Jessica Dembe
@jmdembe
May 06 2016 01:12
Hello! I am on the Quoting Strings with Single Quotes challenge. Can I have a little help?
rphares
@rphares
May 06 2016 01:13
@jmdembe s ure! Can you please paste what you are trying (that isn't working) ? :blush:
Erik Villoria
@kire73
May 06 2016 01:13
if I use toPrecision() or toFixed() they become strings again. If I declare them numbers they stop showing .00 to represent cents
Jessica Dembe
@jmdembe
May 06 2016 01:13
So I put this in
var myStr = <a href='http://www.example.com' target='_blank'>Link</a>;
i removed all the double quotes and backslash, but idk what's wrong
rphares
@rphares
May 06 2016 01:14
ah, okeydoke--
Jessica Dembe
@jmdembe
May 06 2016 01:14
Original code looks like this
var myStr = "<a href=\"http://www.example.com\" target=\"_blank\">Link</a>";
Erik Villoria
@kire73
May 06 2016 01:14
``````function checkCashRegister(price, cash, cid) {
var change = cid.map( e =>[ e[0], 0 ] );
var arr,ncid = [];
var bills = [0.01,0.05,0.10,0.25,1.00,5.00,10.00,20.00,100.00];
var diff = cash - price;
var indrawer = 0;
//Calculate total held by cashier
for (var i = 0; i < cid.length; i++){
indrawer += cid[i][1];
}
//Set change values to 0
for (i = 0 ; i < change.length; i++){
change[i][1] = 0;
}
//Return warnings for special cases
if ( diff > indrawer){
return "Insufficient Funds";
} else if ( diff == indrawer){
return "Closed";
}
//Take change out of each drawer
//according to remaining difference

for (i = 7; i >= 0; i--) {
while (bills[i] <= diff && cid[i][1] >= bills[i]){
cid[i][1] -= bills[i];
diff -= bills[i];
change[i][1].toFixed(2);
change[i][1] += bills[i];
change[i][1].toFixed(2);
}
}

// Here is your change, ma'am.

arr = change.filter(function(ar){
ar[1].toFixed(2);
var o = 0.00;
o = o.toFixed(2);
ar[1] = ar[1].toFixed(2);
return ar[1] !== o;
});

if (diff > 0){
arr[0][1] = Number(arr[0][1]) + 0.01;
}

for (i = 0; i < arr.length; i++){
arr[i][1] = Number(arr[i][1]);

if (arr[i][1] >= 100){
arr[i][1] = arr[i][1].toPrecision(5);
}else if (arr[i][1] >= 10){
arr[i][1] = arr[i][1].toPrecision(4);
} else if (arr[i][1] >= 1){
arr[i][1] = arr[i][1].toPrecision(3);
} else if (arr[i][1] >= 0.1){
arr[i][1] = arr[i][1].toPrecision(2);
}else if (arr[i][1] >= 0.01){
arr[i][1] = arr[i][1].toPrecision(1);
}
}
arr[0][1] = Number(arr[0][1]);
arr[0][1] = arr[0][1].toPrecision(2);
arr.reverse();
return arr;
}
checkCashRegister(19.50, 20.00, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.10], ["QUARTER", 4.25], ["ONE", 90.00], ["FIVE", 55.00], ["TEN", 20.00], ["TWENTY", 60.00], ["ONE HUNDRED", 100.00]]);``````
rphares
@rphares
May 06 2016 01:14
`var myStr` supposed to be a string, right? @jmdembe ?
Jessica Dembe
@jmdembe
May 06 2016 01:14
yes
Diego Mayer
@Chrono79
May 06 2016 01:14
@jmdembe I think you have to left a pair, at the start and at the end
rphares
@rphares
May 06 2016 01:14
So, those get surrounded by quotes,
while we cant use double quotes in this exercise,
we can still use `'`
Jessica Dembe
@jmdembe
May 06 2016 01:15
so surround the URLs by single quotes, right?
rphares
@rphares
May 06 2016 01:15
no-- two things going on in this exercise,
the ones inside the string should all be double--
but we dont want the one inside the string to match the ones surrounding the string,
so the ones on the outside should be `'`
this is the example: `'This string has "double quotes" in it. And "probably" lots of them.'`
see how the strings `'` on the outside edges? and `"` for the quotes inside?
Jessica Dembe
@jmdembe
May 06 2016 01:17
yes, I think so
i'll give this a shot, one second
rphares
@rphares
May 06 2016 01:17
sure thing~
Jessica Dembe
@jmdembe
May 06 2016 01:18
OH YAY IT WORKED!
rphares
@rphares
May 06 2016 01:18
Awesome!
Jessica Dembe
@jmdembe
May 06 2016 01:18
Thanks! @rphares @Chrono79
CamperBot
@camperbot
May 06 2016 01:18
jmdembe sends brownie points to @rphares and @chrono79 :sparkles: :thumbsup: :sparkles:
:star2: 4361 | @rphares |http://www.freecodecamp.com/rphares
rphares
@rphares
May 06 2016 01:18
Please note you could have switched that in real code-- doesn't matter which ones are inside and out-- just in this case they asked for a specific way, so thats all we had to do :blush:
Anytime! Happy coding~
Steve
@smr312
May 06 2016 01:23
so did i do this right?
Erik Villoria
@kire73
May 06 2016 01:23
This message was deleted
Steve
@smr312
May 06 2016 01:23

function timesFive(num) {
return num * 5;
}

Stephen James
@sjames1958gm
May 06 2016 01:24
@smr312 yes
Steve
@smr312
May 06 2016 01:24
alright so if i multiplied any number by 5 it would get the correct answer
Brian
@BrianCodes33
May 06 2016 01:24
why are you setting the same variable
Steve
@smr312
May 06 2016 01:25
should i not?
Clay Shaw
@itsClay
May 06 2016 01:25
its just overlapping it
Brian
@BrianCodes33
May 06 2016 01:25
yea exactly
Erik Villoria
@kire73
May 06 2016 01:25
``````function checkCashRegister(price, cash, cid) {
var change = cid.map( e =>[ e[0], 0 ] );
var arr,ncid = [];
var bills = [0.01,0.05,0.10,0.25,1.00,5.00,10.00,20.00,100.00];
var diff = cash - price;
var indrawer = 0;
//Calculate total held by cashier
for (var i = 0; i < cid.length; i++){
indrawer += cid[i][1];
}
//Set change values to 0
for (i = 0 ; i < change.length; i++){
change[i][1] = 0;
}
//Return warnings for special cases
if ( diff == indrawer){
return "Closed";
} else if ( diff > indrawer || diff > indrawer - 1 ){
return "Insufficient Funds";
}
//Take change out of each drawer
//according to remaining difference

for (i = 7; i >= 0; i--) {
while (bills[i] <= diff && cid[i][1] >= bills[i]){
cid[i][1] -= bills[i];
diff -= bills[i];
change[i][1].toFixed(2);
change[i][1] += bills[i];
change[i][1].toFixed(2);
}
}
//Try to display decimals
arr = change.filter(function(ar){
ar[1].toFixed(2);
var o = 0.00;
o = o.toFixed(2);
ar[1] = ar[1].toFixed(2);
return ar[1] !== o;
});

if (diff > 0){
arr[0][1] = Number(arr[0][1]) + 0.01;
}
//without leaving as strings...
for (i = 0; i < arr.length; i++){
arr[i][1] = Number(arr[i][1]);

if (arr[i][1] >= 100){
arr[i][1] = arr[i][1].toPrecision(5);
}else if (arr[i][1] >= 10){
arr[i][1] = arr[i][1].toPrecision(4);
} else if (arr[i][1] >= 1){
arr[i][1] = arr[i][1].toPrecision(3);
} else if (arr[i][1] >= 0.1){
arr[i][1] = arr[i][1].toPrecision(2);
}else if (arr[i][1] >= 0.01){
arr[i][1] = arr[i][1].toPrecision(1);
}
}
arr.reverse();
return arr;
}
checkCashRegister(19.50, 20.00, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1.00], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]);``````
Clay Shaw
@itsClay
May 06 2016 01:25
better word: overwriting
Steve
@smr312
May 06 2016 01:26
so would this work var answer = timesFive(5, 2, 0);
Brian
@BrianCodes33
May 06 2016 01:26
@smr312 no
Clay Shaw
@itsClay
May 06 2016 01:26
your function only takes one argument so multiple arguments will break it
Steve
@smr312
May 06 2016 01:26
okay okay
Stephen James
@sjames1958gm
May 06 2016 01:27
@smr312 It would work, but only multiply `5 * 5` - javascript is very loose about the number of parameters
Steve
@smr312
May 06 2016 01:27
how would i get t to multiply other numbers? just replace the 5?
Clay Shaw
@itsClay
May 06 2016 01:29
could do something like this
``````var multiplyBy = function (a, b) {
return a * b;
}``````
Steve
@smr312
May 06 2016 01:29
hmmm okay then
that makes more sense now
Clay Shaw
@itsClay
May 06 2016 01:29
but your 5 is hardcoded in purpose, the name eludes to it as well :D
Steve
@smr312
May 06 2016 01:31
Okay
Erik Villoria
@kire73
May 06 2016 01:35
Clay Shaw
@itsClay
May 06 2016 01:42
@kire73 not sure Erik, but can you help me understand whats going on with your callback for my own learning?
``var change = cid.map( e =>[ e[0], 0 ] );``
Erik Villoria
@kire73
May 06 2016 01:44
it creates a copy of cid into change. otherwise modifying change modifies cid. i've noticed the warning about this syntax not being supported but it still works. do you think thats the reason? @itsClay
Jamie MacKillop
@roninCode
May 06 2016 01:44
thought this would be fine, it’s very similar to the example… still only getting “1” as a result and thought it would mutliply the sub arrays by product
friesenet21
@friesenet21
May 06 2016 01:48
help counting cards
CamperBot
@camperbot
May 06 2016 01:48

# Checkpoint: Counting Cards

In the casino game Blackjack, a player can gain an advantage over the house by keeping track of the relative number of high and low cards remaining in the deck. This is called Card Counting.

Having more high cards remaining in the deck favors the player. Each card is assigned a value according to the table below. When the count is positive, the player should bet high. When the count is zero or negative, the player should bet low.

Value Cards
+1 2, 3, 4, 5, 6
0 7, 8, 9
-1 10, 'J', 'Q', 'K','A'

Instructions

You will write a card counting function. It will receive a card parameter and increment or decrement the global count variable according to the card's value (see table). The function will then return the current count and the string "Bet" if the count is positive, or "Hold" if the count is zero or negative.

Example Output:

Clay Shaw
@itsClay
May 06 2016 01:48

try swapping your

``arr[i][j] *= product``

to

``product *= arr[i][j];``
Jamie MacKillop
@roninCode
May 06 2016 01:49
huh ok thank you i wil
Hung Truong
@hungtruong97
May 06 2016 01:50
hi, I accidentally typed the phrase //no protect at the first line and now my page stopped responding. How can I fix that?
Jamie MacKillop
@roninCode
May 06 2016 01:50
ahh very nice thank you!
Stephen
@balomus
May 06 2016 01:50
``````
function getIndexToIns(arr, num) {
// Find my place in this sorted array.

arr.sort(function(a, b){
return a - b;
});

for(i = 0; i < arr.length; i++)
{
if(arr[i] > num)
{
arr.splice(i, 0, num);
}
}

return arr;
}

getIndexToIns([60, 40], 50);``````
Can someone explain to me why this is an infinite loop?
Hung Truong
@hungtruong97
May 06 2016 01:53
no protect
Stephen
@balomus
May 06 2016 01:54
@hungtruong97 I see the hint that I can use the `// noprotect` to run the code anyway, but it just crashes the browser.
Hung Truong
@hungtruong97
May 06 2016 01:56
@balomus Do you know how to make it run again? I tried closing the tab and opening it again but it is still not responding.
Stephen
@balomus
May 06 2016 01:56
I received a prompt saying "the script has stopped responding, stop it or wait?" and I could click stop script
I'm using Firefox if that helps
I still don't fully understand why it's an infinite for loop though
Jacob Bogers
@jacobbogers
May 06 2016 01:58
can I get some feedbackfrom mobile users?
eduwin7
@eduwin7
May 06 2016 02:01
need help
Dylan
@dhcodes
May 06 2016 02:02
@jacobbogers works great. The author text is a little small on mobile and desktop
@jacobbogers you can do a loose test of "mobile" just by shrinking your window
That's a cool idea with the animation btw
Clay Shaw
@itsClay
May 06 2016 02:03
or if you use chrome there is a mobile view you can customize
VultureBetrayer
@VultureBetrayer
May 06 2016 02:04
I am totally confused by the Stand In Line problem, I don't even understand what they want me to learn
how would I ask a question to get help?
eduwin7
@eduwin7
May 06 2016 02:05

function testSize(num) {
// Only change code below this line
if (num < 5 ){
return "Tiny";
} else if (num < 10){
return "Small";
}
else if (num < 15){
return "Medium";
} else if (num < 20){
return "Large";
}
else if (num <=20){
return "Huge";
}
else if (num < 25)
return "Huge";

}

i am on chaining if else statements
VultureBetrayer
@VultureBetrayer
May 06 2016 02:06
missing a closing bracket I think
Angelo Ryndon
@AIRyndon
May 06 2016 02:06
@VultureBetrayer
``````
function nextInLine(arr, item) {

arr.push(item);

return arr.shift();  // Change this line
}``````
VultureBetrayer
@VultureBetrayer
May 06 2016 02:07
how do you post the code view like this?
Dylan
@dhcodes
May 06 2016 02:07
@AIRyndon well i'm not so sure giving him the answer helps him learn anything
Angelo Ryndon
@AIRyndon
May 06 2016 02:07
@VultureBetrayer A queue is like a line in a bank
Dylan
@dhcodes
May 06 2016 02:07
@VultureBetrayer they are teaching you two array methods, push and shift
Angelo Ryndon
@AIRyndon
May 06 2016 02:07
when someone in front is done he leaves
Dylan
@dhcodes
May 06 2016 02:07
thanks for following up @AIRyndon
CamperBot
@camperbot
May 06 2016 02:07
dhcodes sends brownie points to @airyndon :sparkles: :thumbsup: :sparkles:
Angelo Ryndon
@AIRyndon
May 06 2016 02:07
people enter from the back :smile:
@dhcodes :smile:
VultureBetrayer
@VultureBetrayer
May 06 2016 02:08
I think we are talking about 2 different problems @AIRyndon
how do I post the code view?
Dylan
@dhcodes
May 06 2016 02:08
help code format
CamperBot
@camperbot
May 06 2016 02:08

## :point_right: code formatting [wiki]

### Multi line Code

```js ⇦ Type 3 backticks and then press `[shift + enter ⏎]` (type js or html or css)

``````<paste your code here>,
then press [shift + enter ⏎]``````

``` ⇦ Type 3 backticks, then press `[enter ⏎]`

### Single line Code

This an inline ``<paste code here>`` code formatting with a single backtick(`) at start and end around the `code`.

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

Dylan
@dhcodes
May 06 2016 02:08
you put three backticks ```
then three more backticks ```
VultureBetrayer
@VultureBetrayer
May 06 2016 02:09
ahhh cool thanks
eduwin7
@eduwin7
May 06 2016 02:09

,,,function testSize(num) {
// Only change code below this line
if (num < 5 ){
return "Tiny";
} else if (num < 10){
return "Small";
}
else if (num < 15){
return "Medium";
} else if (num < 20){
return "Large";
}
else if (num <=20){
return "Huge";
}
else if (num < 25)
return "Huge";

}

cant get 25 to return "hug"
Huge
Dylan
@dhcodes
May 06 2016 02:10
@eduwin7 you need an opening bracket on your last else if
for one thing
Jacob Bogers
@jacobbogers
May 06 2016 02:10
@dhcodes I removed the animation what do you think , better? http://codepen.io/jacobBogers/full/mPaKZe/
reduced, not removed
Dylan
@dhcodes
May 06 2016 02:10
I liked the animation
eduwin7
@eduwin7
May 06 2016 02:10
function testSize(num) {
// Only change code below this line
if (num < 5 ){
return "Tiny";
} else if (num < 10){
return "Small";
}
else if (num < 15){
return "Medium";
} else if (num < 20){
return "Large";
}
else if (num <=20){
return "Huge";
}
else if
(num < 25){
return "Huge";
Dylan
@dhcodes
May 06 2016 02:10
I might make it a touch faster if possible @jacobbogers
eduwin7
@eduwin7
May 06 2016 02:10
still not returning Huge
VultureBetrayer
@VultureBetrayer
May 06 2016 02:10

```function nextInLine(arr, item) {

return item; // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));
```

goddamnit
``````function nextInLine(arr, item) {

return item;  // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));``````
Jacob Bogers
@jacobbogers
May 06 2016 02:11
faster animation
Dylan
@dhcodes
May 06 2016 02:11
nice @VultureBetrayer
Jacob Bogers
@jacobbogers
May 06 2016 02:11
mmm, i can do fater , moment
VultureBetrayer
@VultureBetrayer
May 06 2016 02:11
so I'm totally confused on this problem, I don't understand what they want me to do at all
Dylan
@dhcodes
May 06 2016 02:11
help chaining if else statements
CamperBot
@camperbot
May 06 2016 02:11

# Challenge: Chaining If Else Statements

`if/else` statements can be chained together for complex logic. Here is `pseudocode` of multiple chained `if` / `else if` statements:

``````if(condition1) {
statement1
} else if (condition2) {
statement2
} else if (condition3) {
statement3
. . .
} else {
statementN
}``````
VultureBetrayer
@VultureBetrayer
May 06 2016 02:11
Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed
thats the challenge, but it doesn't really fall back on any previous lessons
Dylan
@dhcodes
May 06 2016 02:12
@VultureBetrayer what @AIRyndon was explaining was right
imagine the array is a line of people
Jacob Bogers
@jacobbogers
May 06 2016 02:12
@dhcodes I doubled the speed http://codepen.io/jacobBogers/pen/mPaKZe
Dylan
@dhcodes
May 06 2016 02:12
they are teaching you two methods on arrays, push and shift
VultureBetrayer
@VultureBetrayer
May 06 2016 02:12
I get that, I don't understand what they want me to return
Dylan
@dhcodes
May 06 2016 02:12
push adds an item at the end of the array
shift removes the first element and returns it
they want you to add the item and then return (shift) the first item in the array
@VultureBetrayer
VultureBetrayer
@VultureBetrayer
May 06 2016 02:13
ughgh, that's annoying I wish the lessons didn't switch between methods so much, there's no way to practice push and shift and that's 5 lessons behind this one
Dylan
@dhcodes
May 06 2016 02:13
@jacobbogers maybe i liked it better before. I guess it's just a performance issues that causes a big of a delay
lol
VultureBetrayer
@VultureBetrayer
May 06 2016 02:14
but thanks I'll just try and make it work
Dylan
@dhcodes
May 06 2016 02:14
Shirman
@Shirman
May 06 2016 02:14
why it's not work rightly
thank all

function sumFibs(num) {
var fiboArr = [0,1];
var fibo = 0;
var idx = 2;
while(fibo <= num){
fibo = fiboArr[idx - 1] + fiboArr[idx - 2];
if(fibo <=　num){
fiboArr.push(fibo);
}
idx++;
}
return fiboArr.reduce(function(pre,curr){
return pre + curr;
});
}

sumFibs(4);

Dylan
@dhcodes
May 06 2016 02:16
@eduwin7 it says if num >= 20
you have > 25
@eduwin7
num < 5 - return "Tiny"
num < 10 - return "Small"
num < 15 - return "Medium"
num < 20 - return "Large"
num >= 20 - return "Huge"
Ray
@raymondhw
May 06 2016 02:17
var myStr="I am a \"double quoted \"string inside \"double quotes\""; Can someone help me, free camp isnt passing this but it out puts as the right answer
meant to say free code camp. I think there might be a bug and help would be awesome
Norvin Burrus
@ndburrus
May 06 2016 02:18
@VultureBetrayer The first step is: "Add the number to the end of the array, then remove the first element of array. " The function "nextInLine" has been provided for/to you.
Ray
@raymondhw
May 06 2016 02:19
use backlashes to assign a string
VultureBetrayer
@VultureBetrayer
May 06 2016 02:22
ok this still doesn't make any sense
Norvin Burrus
@ndburrus
May 06 2016 02:22
@VultureBetrayer ok, do you understand the function statement?
VultureBetrayer
@VultureBetrayer
May 06 2016 02:23
I do
I just don't understand the syntax of how I'm supposed to do this to the array
Norvin Burrus
@ndburrus
May 06 2016 02:23
@VultureBetrayer alrighty... do you see that the function "nextInLine" receives two items?
VultureBetrayer
@VultureBetrayer
May 06 2016 02:23
the prior items never had us do push or shift on more than one data set so I'm confused on how you are supposed to even know what to do
``````
function nextInLine(arr, item) {

nextInLine.push([item]);
nextInLine.shift([arr]);// Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));``````
Norvin Burrus
@ndburrus
May 06 2016 02:24
@VultureBetrayer ...relax....let's take this one step at a time, shall we?
VultureBetrayer
@VultureBetrayer
May 06 2016 02:24
thats all I can think of but its obviously totally wrong
Norvin Burrus
@ndburrus
May 06 2016 02:25
@VultureBetrayer ok, i understand you concern/s... let's proceed slowly - you'll get it....
Ray
@raymondhw
May 06 2016 02:25
wow, i cant get any help people!!!
Norvin Burrus
@ndburrus
May 06 2016 02:25
@ray503 hi ray... what are you working on?
VultureBetrayer
@VultureBetrayer
May 06 2016 02:25
so add the number to the end of the array, that's a push
Ray
@raymondhw
May 06 2016 02:26

Use backslashes to assign a string to the myStr variable so that if you were to print it to the console, you would see:

I am a "double quoted" string inside "double quotes"

VultureBetrayer
@VultureBetrayer
May 06 2016 02:26
``nextInLine.push([],item);``
???
Norvin Burrus
@ndburrus
May 06 2016 02:26
@VultureBetrayer right... now what are we push/ing the number onto? btw, let's check out notation/s....
VultureBetrayer
@VultureBetrayer
May 06 2016 02:26
to the end of the array correct?
Ray
@raymondhw
May 06 2016 02:27
This is my answer, it out puts it ass being correct put it wont pass me. -> var myStr="I am a \"double quoted \"string inside \"double quotes\"";
VultureBetrayer
@VultureBetrayer
May 06 2016 02:28
Ray
Norvin Burrus
@ndburrus
May 06 2016 02:28
@VultureBetrayer yes, tha's correct.... this may be useful:
``````SyntaxEDIT
arr.push(element1, ..., elementN)``````
VultureBetrayer
@VultureBetrayer
May 06 2016 02:28
@ray503 use single quotes for your opening and closing quotes
Ray
@raymondhw
May 06 2016 02:28
yes im here
VultureBetrayer
@VultureBetrayer
May 06 2016 02:28
its something they mention in passing
Ray
@raymondhw
May 06 2016 02:29
what do you mean?
Norvin Burrus
@ndburrus
May 06 2016 02:29
@VultureBetrayer ok, can we correct the notation for the push statement?
VultureBetrayer
@VultureBetrayer
May 06 2016 02:29
so do I need to assign each array element first? like make 5 array elements and add item to the back?
nextInLine.push([],[],[],[],[],item);
like that?
Norvin Burrus
@ndburrus
May 06 2016 02:30
@VultureBetrayer let's slow down and get each successive piece right....
VultureBetrayer
@VultureBetrayer
May 06 2016 02:30
@ray503 use a ' rather than a " for your opening and closing quotes
Clay Shaw
@itsClay
May 06 2016 02:30
@balomus I have to run, but was playing with your code and it has to do with the splice method, try this code out.
``````function getIndexToIns(arr, num) {
// Find my place in this sorted array.

arr.sort(function(a, b) {
return b - a;
});

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

console.log(arr)
return arr;
}

getIndexToIns([60, 40], 50);``````
i think thats what you were looking for.
VultureBetrayer
@VultureBetrayer
May 06 2016 02:30
gotcha, too much coffee and hair pulling today
Norvin Burrus
@ndburrus
May 06 2016 02:32
@VultureBetrayer alright... lets get the push statement right. how would we write that statement? did you see the syntax post (for a push statement)?
VultureBetrayer
@VultureBetrayer
May 06 2016 02:32
oh wait, so I'm not editing the nextInLine array? but the element arr?
Hung Truong
@hungtruong97
May 06 2016 02:32
can anybody tell me what's wrong with this code?
``````function mutation(arr) {
var array = arr[1].slice("");

for (i = 0; i<array.length; i++) {
if (arr[0].indexOf(array[i]) < 0) {
return false;
} else return true;
}
}

mutation(["hello", "hey"]);``````
Islam Ibakaev
@dagman
May 06 2016 02:33
@hungtruong97 what it should do?
VultureBetrayer
@VultureBetrayer
May 06 2016 02:33
isn't that missing an elseif ?
Norvin Burrus
@ndburrus
May 06 2016 02:33
@VultureBetrayer no, you are not. that is correct. notice where it says "your code here." that means enter your code below that statement (or comment).
Hung Truong
@hungtruong97
May 06 2016 02:34
@dagman I should check if all the letters in the second element of the array are in the first element
Angelo Ryndon
@AIRyndon
May 06 2016 02:34
``````
function repeatStringNumTimes(str, num) {
// repeat after me
return (num >=0)?str.repeat(num):"";
}

repeatStringNumTimes("abc", 3);``````
Halo Guys! its the repeat String Challenge. How do I write this without relying on the repeat method? I'm ashamed I can't hard-code it. :worried: I tried converting it to an array then adding values from inside the array..Can't seem to make it work..brb in a few minutes :smile:
Islam Ibakaev
@dagman
May 06 2016 02:34
@hungtruong97 maybe you need split instead of slice
VultureBetrayer
@VultureBetrayer
May 06 2016 02:34
ahhh ok so the return statement needs to stay? I'm confused because it says to change that line
Ronique Ricketts
@RoniqueRicketts
May 06 2016 02:35
Sigh I still dont get whats wrong with my code.
Norvin Burrus
@ndburrus
May 06 2016 02:35
@VultureBetrayer one thing at a time. you're jumping all around. it is difficult to get a step accomplished if you do that.... :)
Diego Mayer
@Chrono79
May 06 2016 02:35
@AIRyndon why don't you use += operator inside a loop?
Islam Ibakaev
@dagman
May 06 2016 02:35
@hungtruong97 and u cant return true in else statement
VultureBetrayer
@VultureBetrayer
May 06 2016 02:36
gotcha
Norvin Burrus
@ndburrus
May 06 2016 02:36
@VultureBetrayer would you like to correct the push statement now? and did you notice the post concerning the push statement format/ting?
Ronique Ricketts
@RoniqueRicketts
May 06 2016 02:37
``````var collectionCopy = JSON.parse(JSON.stringify(collection));

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

if (value !=="" && prop !== "tracks"){
collection.id=[prop,value];
}
else if (prop==="tracks" && value !==""){
collection.tracks.push(value);
}
else {
delete collection.id.prop;}

}``````
VultureBetrayer
@VultureBetrayer
May 06 2016 02:37

so I tried this push statement:

```
arr.push(item);

Islam Ibakaev
@dagman
May 06 2016 02:37
@hungtruong97 otherwise you will not be able to check all letters
VultureBetrayer
@VultureBetrayer
May 06 2016 02:38
``arr.push(item);``
Norvin Burrus
@ndburrus
May 06 2016 02:38
@VultureBetrayer ok, now we are making progress... :)
Hung Truong
@hungtruong97
May 06 2016 02:38
@dagman I changed my code to this:
```js
Diego Mayer
@Chrono79
May 06 2016 02:39
@RoniqueRicketts
`collection.tracks.push(value);`missing id
`delete collection.id.prop;` can't use dot notation, use bracket notation
Hung Truong
@hungtruong97
May 06 2016 02:39
``````function mutation(arr) {
var array = arr[1].split("");

for (i = 0; i<array.length; i++) {
if (arr[0].indexOf(array[i]) >= 0) {
j =true;
} else j = false;
} return j;
}

mutation(["hello", "hey"]);``````
Norvin Burrus
@ndburrus
May 06 2016 02:39
@VultureBetrayer can u post your code?
Ivan
@gonzalezi2
May 06 2016 02:39
hey guys just wanted to see if I could get some help with this temperature converter
VultureBetrayer
@VultureBetrayer
May 06 2016 02:39
`````` function nextInLine(arr, item) {

arr.push(item);
arr.shift([]);

return item;  // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));``````
that's where I'm at
Hung Truong
@hungtruong97
May 06 2016 02:39
it returned "hello", "hey" false, but "hello", "neo" true
Diego Mayer
@Chrono79
May 06 2016 02:40
@VultureBetrayer why shift([]) ?
Hung Truong
@hungtruong97
May 06 2016 02:40
i dont know why
VultureBetrayer
@VultureBetrayer
May 06 2016 02:40
trying to remove the first element of the array
Diego Mayer
@Chrono79
May 06 2016 02:40
@VultureBetrayer shift has no parameters
Norvin Burrus
@ndburrus
May 06 2016 02:40
@VultureBetrayer ok, great. let me take a look.
VultureBetrayer
@VultureBetrayer
May 06 2016 02:41
that's why I'm confused, the explanation of this process is pretty hard to understand, if I had example code I'd get it in a minute
Ivan
@gonzalezi2
May 06 2016 02:41

function convertToF(celsius) {
// Only change code below this line
var fahrenheit = celcius * 9/5 + 32;

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

// Change the inputs below to test your code
convertToF(30);

Islam Ibakaev
@dagman
May 06 2016 02:41
@hungtruong97 i think previous was good just needed some fixing
``````
function mutation(arr) {
var array = arr[1].split(""),  i;
for (i = 0; i<array.length; i++) {
if (arr[0].indexOf(array[i]) < 0) {
return false;
}
}
return true;
}

mutation(["hello", "hey"]);``````
Diego Mayer
@Chrono79
May 06 2016 02:41
@gonzalezi2 it's celsius, not celcius
Norvin Burrus
@ndburrus
May 06 2016 02:41
@VultureBetrayer now we want to "remove the first element of array" how would we do that? response to your comment: well, what we're doing now is translating the verbage (requirement/s) into code.... that's all.... :)
VultureBetrayer
@VultureBetrayer
May 06 2016 02:42
ohhhhh it's pop not shift
Diego Mayer
@Chrono79
May 06 2016 02:42
@VultureBetrayer no, it's shift, you have to either return it of store it in a var and return that
Ivan
@gonzalezi2
May 06 2016 02:42
do'h
Ronique Ricketts
@RoniqueRicketts
May 06 2016 02:43
@Chrono79 still doesn't work
Ivan
@gonzalezi2
May 06 2016 02:43
thanks @Chrono79
CamperBot
@camperbot
May 06 2016 02:43
gonzalezi2 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
VultureBetrayer
@VultureBetrayer
May 06 2016 02:43
arr.shift(item);
Diego Mayer
@Chrono79
May 06 2016 02:43
@RoniqueRicketts this isn't right either: `collection.id=[prop,value];`
VultureBetrayer
@VultureBetrayer
May 06 2016 02:43
``arr.shift(item);``
Diego Mayer
@Chrono79
May 06 2016 02:44
@VultureBetrayer no parameter inside shift(), you can do it like this: `item = arr.shift();`and return item or simply `return arr.shift();`
Ronique Ricketts
@RoniqueRicketts
May 06 2016 02:44
oh
VultureBetrayer
@VultureBetrayer
May 06 2016 02:44
except that obviously doesnt work because we already did push on the same element
you can shift with an empty element to clear an item from the array?
Lurk
@reformedRattlesnake
May 06 2016 02:45
@VultureBetrayer Shift always removes the first element in an array, so you can't give it an argument. Just like pop always kicks the final element.
VultureBetrayer
@VultureBetrayer
May 06 2016 02:45
``````  arr.push(item);
arr.shift();``````
so like this?
Norvin Burrus
@ndburrus
May 06 2016 02:46
@VultureBetrayer review:
``````Methods pop and push

There is a method pop which removes last item and returns it.

The following example demonstrates how the “Donkey” is being popped out.

Run!
1
var fruits = ["Apple", "Orange", "Donkey"]
2

3
4

5
// Now we have ["Apple","Orange"]
6

7
alert("Now length is: "+fruits.length) // donkey removed
Note how pop modifies the array itself.

A counterpart to pop is push which appends an element to the array. Let’s say we’ve forgotten a peach:

Run!
1
var fruits = ["Apple", "Orange"]
2

3
fruits.push("Peach");
4

5
// now got ["Apple", "Orange", "Peach"]
6

7
Create an array styles with elements “Jazz”, “Blues”.
Append a value “Rock’n’Roll”
Replace the second value from tail by “Classic”. The array should become “Jazz”,”Classic”,”Rock’n’Roll”. The code should work for any array length.
Extract the last value from the array and alert it.
Open solution
Methods shift/unshift

Methods pop/push manipulate with the end of array, but you can also use shift to shift off first value or unshift to prepend a value to an array.

Run!
1
var fruits = ["Apple", "Orange"]
2

3
var apple = fruits.shift() // now we have only ["Orange"] left
4

5
fruits.unshift("Lemon") // now got ["Lemon", "Orange"]
6

7
Both push and unshift can add multiple elements at once:

Run!
1
var fruits = ["Apple"]
2

3
fruits.push("Orange","Peach")
4
fruits.unshift("Pineapple","Lemon")
5

6
// now: ["Pineapple", "Lemon", "Apple", "Orange", "Peach"]``````
Diego Mayer
@Chrono79
May 06 2016 02:46
@VultureBetrayer yes
try this: (not in this challenge)
``````arr = [1,2,3,4];
console.log(arr.shift("I'm the king of the hill")); // it's 1 and what you put inside shift() is ignored``````
Hung Truong
@hungtruong97
May 06 2016 02:46
@dagman thanks so much, it worked. I am always confused when to return value in a for loop
CamperBot
@camperbot
May 06 2016 02:46
hungtruong97 sends brownie points to @dagman :sparkles: :thumbsup: :sparkles:
VultureBetrayer
@VultureBetrayer
May 06 2016 02:47
``````
function nextInLine(arr, item) {

arr.shift();
arr.push(item);

return item;  // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));``````
Here's where I'm at
Islam Ibakaev
@dagman
May 06 2016 02:47
@hungtruong97 when you returns true in else you will be return true after first letter get checked but it is not a case
Diego Mayer
@Chrono79
May 06 2016 02:48
@VultureBetrayer you can do it like this: item = arr.shift();and return item or simply return arr.shift();
As I said before.
Norvin Burrus
@ndburrus
May 06 2016 02:48
This message was deleted
Lurk
@reformedRattlesnake
May 06 2016 02:48
@VultureBetrayer If you want to know what got removed, you'll need to save the result of shifting in a variable, like @Chrono79 mentioned above, or just... that. hehe
Angelo Ryndon
@AIRyndon
May 06 2016 02:49
`````` function repeatStringNumTimes(str, num) {
// repeat after me
/*
var newString = "";
if(num >=0)
{
for(var i = 0; i < num.length;i++)
{
newString += str;
}
}
else
newString = "";

return newString;
*/``````
I was doing num.length on an Integer....talk about facepalm moments LOL
Lurk
@reformedRattlesnake
May 06 2016 02:49
Nice!
Angelo Ryndon
@AIRyndon
May 06 2016 02:49
Btw how else do we check for a negative number? other than num >= 0 ?
Diego Mayer
@Chrono79
May 06 2016 02:50
@AIRyndon num<0 ?
Angelo Ryndon
@AIRyndon
May 06 2016 02:51
@Chrono79 I mean without using those operators, no other way? hehehe..was just curious
Diego Mayer
@Chrono79
May 06 2016 02:51
@AIRyndon Math.abs(num) !== num, why reinvent the wheel?
Lurk
@reformedRattlesnake
May 06 2016 02:52
Norvin Burrus
@ndburrus
May 06 2016 02:53
@VultureBetrayer did you get it?
Angelo Ryndon
@AIRyndon
May 06 2016 02:54
I'm not even familiar with the Math class in Javascript.. Thanks @Chrono79 .. :smile:
CamperBot
@camperbot
May 06 2016 02:54
airyndon sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
Anurag Lahon
@anuraglahon16
May 06 2016 02:54
([40, 60], 50);
how can we get the index of this array?
Lurk
@reformedRattlesnake
May 06 2016 02:55
@anuraglahon16 How do you mean, the index of the array?
Angelo Ryndon
@AIRyndon
May 06 2016 02:55

@anuraglahon16

I think there is that special arguments object in a function

VultureBetrayer
@VultureBetrayer
May 06 2016 02:55
``````function nextInLine(arr, item) {

arr.push(item);

item = arr.shift();

return item;  // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));``````

ok this works, can you help me to understand what's happening here please? I just want to make sure I grok the meaning. . .

I'm seeing it push item to the end of arr, but I'm having a hard time understanding how arr is an array

Angelo Ryndon
@AIRyndon
May 06 2016 02:56
you can hit that argument from there...if it is an argument
Diego Mayer
@Chrono79
May 06 2016 02:56
@VultureBetrayer you call your function in this line:
`console.log(nextInLine(testArr, 6)); // Modify this line to test`
// Test Setup
`var testArr = [1,2,3,4,5];`
`function nextInLine(arr, item) {` so arr takes testArr value
Lurk
@reformedRattlesnake
May 06 2016 02:57
@VultureBetrayer arr is a parameter. You provide the array as an argument to the function - in this case, testArr. So wherever you see arr, it's replacing it with testArr (or whatever other provided array)
Anurag Lahon
@anuraglahon16
May 06 2016 02:57
getIndexToIns([10, 20, 30, 40, 50], 35) should return 3. ......first we sort it then ...for loop it i guess n how to find the index here......in a string we use the function index()
@reformedRattlesnake
@AIRyndon
VultureBetrayer
@VultureBetrayer
May 06 2016 02:57
so item=arr.shift(); is taking the array and cutting off the first part
Norvin Burrus
@ndburrus
May 06 2016 02:57
@VultureBetrayer the challenge says "nextInLine which takes an array (arr) "
VultureBetrayer
@VultureBetrayer
May 06 2016 02:58
and arr.push(item) just posts it at the end?
so an element of a function can be either a var or an array? and that doesn't matter ?
I think that's what's screwing with my brain, I thought all elements of a function had to be a single defined variable
Diego Mayer
@Chrono79
May 06 2016 02:59
@VultureBetrayer go here: http://www.pythontutor.com/javascript.html#mode=display and copy and paste your code
Norvin Burrus
@ndburrus
May 06 2016 02:59
@VultureBetrayer arr.push puts the number "to the end of the array". arr.shift() "remove[s] the first element of array."
VultureBetrayer
@VultureBetrayer
May 06 2016 02:59
oh man! holy crap that website is amazing
Norvin Burrus
@ndburrus
May 06 2016 03:01
@VultureBetrayer i like this one (a repl): https://repl.it/
VultureBetrayer
@VultureBetrayer
May 06 2016 03:02
these are both incredibly helpful, thanks both of you for stepping through this with me
Diego Mayer
@Chrono79
May 06 2016 03:02
no problem
Lurk
@reformedRattlesnake
May 06 2016 03:02
@VultureBetrayer By element of a function do you mean parameters? If so, it might be more clear to think of the parameters as variables, the arguments as values. When you're defining a function and using things like arr, element, string, whatever, they're variables. They don't have a value until you pass in 'dog' testArray etc as arguments. Sorry if that's not helpful.
Norvin Burrus
@ndburrus
May 06 2016 03:03
@VultureBetrayer ...anytime!! hey i like the other one too... it's awesome! :+1:
VultureBetrayer
@VultureBetrayer
May 06 2016 03:03
that's what I meant lurk, I was confused if the parameters were variables or were array elements, I was thinking of them as single array elements
so I was thinking the function was an array declaration within the function
erm. . let me rephrase
Michael Kuang
@kuangmichael07
May 06 2016 03:04
``````var args = Array.prototype.slice.call(arguments);
args.sort(function(a, b){return a-b;});``````
does anybody know why the error says: args.sort is not a function?
VultureBetrayer
@VultureBetrayer
May 06 2016 03:04
I was thinking the parameters were array elements
Michael Kuang
@kuangmichael07
May 06 2016 03:04
This message was deleted
Diego Mayer
@Chrono79
May 06 2016 03:05
Michael Kuang
@kuangmichael07
May 06 2016 03:05
This message was deleted

@Chrono79

``````function uniteUnique(arr1, arr2, arr3) {
var args = Array.prototype.slice.call(arguments);
args.sort(function(a, b){return a-b;});
var arrUniq = args.reduce(function(a, b) {
if (a !== b) {
return a.concat(b);
}
});
return arrUniq;
}
uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);``````

Here is it
This is the Sorted Union

Christina
@cgraham74
May 06 2016 03:08
help fibonacci numbers
CamperBot
@camperbot
May 06 2016 03:08

# Explanation:

You will need to gather all the Fibonacci numbers and then check for the odd ones. Once you get the odd ones then you will add them all. The last number should be the number given as a parameter if it actually happens to be an off Fibonacci number.

Diego Mayer
@Chrono79
May 06 2016 03:10
@kuangmichael07 I don't get that error, but also it's not sorting because args is an array of arrays, so b - a has no sense there
Michael Kuang
@kuangmichael07
May 06 2016 03:10
CamperBot
@camperbot
May 06 2016 03:10
kuangmichael07 sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
Islam Ibakaev
@dagman
May 06 2016 03:13
@kuangmichael07 u dont need `arguments` object
it is an object of arrays to be exact :smile:
Diego Mayer
@Chrono79
May 06 2016 03:14
@dagman I think he does, look at this test: uniteUnique([1, 2, 3], [5, 2, 1, 4], [2, 1], [6, 7, 8]) should return [1, 2, 3, 5, 4, 6, 7, 8] or I didn't understand what you mean
Islam Ibakaev
@dagman
May 06 2016 03:15
@Chrono79 i was saying he doesnt need do it this way cos he has params included
Diego Mayer
@Chrono79
May 06 2016 03:16
@dagman yes, but look at that test, it has 4 "params", and only 3 defined in the function
Islam Ibakaev
@dagman
May 06 2016 03:16
@Chrono79 which test
Diego Mayer
@Chrono79
May 06 2016 03:17
uniteUnique([1, 2, 3], [5, 2, 1, 4], [2, 1], [6, 7, 8]) should return [1, 2, 3, 5, 4, 6, 7, 8]
Johnny K Juarez
@Reapnsow
May 06 2016 03:17

I'm stuck on Replacing if Else Chains with Switch, and I think i'm missing something important in my code which may be obvious but i'm not seeing it.

switch (val){
case "bob":
break;
case 42:
break;
case 1:
answer = "There is no #1";
break;
case 99:
answer = "Missed me by this much!";
break;
case 7:
break;
}

Islam Ibakaev
@dagman
May 06 2016 03:17
@Chrono79 he provided three arrays
where did u get this?
Diego Mayer
@Chrono79
May 06 2016 03:18
well, that test is in the challenge
Norvin Burrus
@ndburrus
May 06 2016 03:18
@Reapnsow is val defined?
Johnny K Juarez
@Reapnsow
May 06 2016 03:19

@ndburrus
full code

function chainToSwitch(val) {
// Only change code below this line

switch (val){
case "bob":
break;
case 42:
break;
case 1:
answer = "There is no #1";
break;
case 99:
answer = "Missed me by this much!";
break;
case 7:
break;
}
// Only change code above this line

}

// Change this value to test
chainToSwitch(7);

Diego Mayer
@Chrono79
May 06 2016 03:20
Jeff
@meankraken
May 06 2016 03:20
Hey all I'm having a really weird issue... every time I try to view something on codepen, the editor view will just show Loading.... but in full page view I can see the project
VultureBetrayer
@VultureBetrayer
May 06 2016 03:20
@Reapnsow did you know you can do ``` (shift + enter) paste your code then hit (CTRL + enter) to get it to show as a code window?
Islam Ibakaev
@dagman
May 06 2016 03:20
@Chrono79 oh i found it you were right :+1:
Johnny K Juarez
@Reapnsow
May 06 2016 03:21
@Chrono79 doesn't say to use a return.
VultureBetrayer
@VultureBetrayer
May 06 2016 03:21
@meankraken sounds like a browser issue, got any plugins running?
Johnny K Juarez
@Reapnsow
May 06 2016 03:21
@VultureBetrayer I did not, thank you
CamperBot
@camperbot
May 06 2016 03:21
reapnsow sends brownie points to @vulturebetrayer :sparkles: :thumbsup: :sparkles:
Jeff
@meankraken
May 06 2016 03:21
@VultureBetrayer that's what I thought too, but I switched over to internet explorer... exact same thing
VultureBetrayer
@VultureBetrayer
May 06 2016 03:21
what browser you using?
Jeff
@meankraken
May 06 2016 03:21
@VultureBetrayer also note this happened while I was in the middle of coding one of my projects
VultureBetrayer
@VultureBetrayer
May 06 2016 03:21
interesting
can you link the code pen page? maybe it's something screwy we all see
Norvin Burrus
@ndburrus
May 06 2016 03:22
@Reapnsow did you get rid of the return statement?
Jeff
@meankraken
May 06 2016 03:22
@VultureBetrayer the thing is it happens on every single page
@VultureBetrayer even random pens from the front page.. editor view shows Loading... but I can view in full page view mode
VultureBetrayer
@VultureBetrayer
May 06 2016 03:23
sounds to me like browser cache or something, did you reboot?
Johnny K Juarez
@Reapnsow
May 06 2016 03:23
@ndburrus this is what i have.
``````
function chainToSwitch(val) {
// Only change code below this line

switch (val){
case "bob":
break;
case 42:
break;
case 1:
answer = "There is no #1";
break;
case 99:
answer = "Missed me by this much!";
break;
case 7:
break;
}
// Only change code above this line

}

// Change this value to test
chainToSwitch(7);``````
VultureBetrayer
@VultureBetrayer
May 06 2016 03:23
also maybe cookies and cache? not sure if your browsers are sharing the temp folder
Jeff
@meankraken
May 06 2016 03:24
@VultureBetrayer yeah tried rebooting, issue remained
Norvin Burrus
@ndburrus
May 06 2016 03:24
@Reapnsow where is return answer; ? that piece of code should not have been changed/removed...
Lurk
@reformedRattlesnake
May 06 2016 03:24
@Reapnsow Even if it doesn't explicitly say to add one, if you don't tell your function to return something, it will return undefined. So even though you have all those answer possibilities, you're not doing anything with them... hehe.
Diego Mayer
@Chrono79
May 06 2016 03:24
@Reapnsow
``````  // Only change code above this line
return answer;  // you deleted this line``````
VultureBetrayer
@VultureBetrayer
May 06 2016 03:24
do you know how to clear cookies and cache?
Lurk
@reformedRattlesnake
May 06 2016 03:25
hehehe
Anurag Lahon
@anuraglahon16
May 06 2016 03:25

function getIndexToIns(arr, num) {
// Find my place in this sorted array.
var array=arr.sort();
for(var i=0;i<=array.length;i++)
{
if(array[i]<=num)

`````` {
return array.indexOf(array[i]);
}

}``````

}

getIndexToIns([40, 60], 50);

wt is wrong there
Norvin Burrus
@ndburrus
May 06 2016 03:25
@Reapnsow
``````function chainToSwitch(val) {
// Only change code below this line

switch (val) {
case "bob":
break;
case 42:
break;
case 1:
answer = "There is no #1";
break;
case 99:
answer = "Missed me by this much!";
break;
case 7:
break;
}

// Only change code above this line
}

// Change this value to test
chainToSwitch(7);``````
Johnny K Juarez
@Reapnsow
May 06 2016 03:25
@reformedRattlesnake , @ndburrus , @Chrono79 thanks.
CamperBot
@camperbot
May 06 2016 03:25
reapnsow sends brownie points to @reformedrattlesnake and @ndburrus and @chrono79 :sparkles: :thumbsup: :sparkles:
Norvin Burrus
@ndburrus
May 06 2016 03:26
@Reapnsow welcome!! :sparkles:
Diego Mayer
@Chrono79
May 06 2016 03:26
@anuraglahon16 you return at the first value that's lesser or equal than num
in the call you have there, [40,60] , 50, you return 0 meaning you should insert 50 in the index 0 getting [50, 40, 60]
Anurag Lahon
@anuraglahon16
May 06 2016 03:27
@Chrono79 getIndexToIns([10, 20, 30, 40, 50], 35) should return 3.
VultureBetrayer
@VultureBetrayer
May 06 2016 03:29
oh crap, how do I send brownie points?
Diego Mayer
@Chrono79
May 06 2016 03:29
@anuraglahon16 another thing that's wrong is your sort, it doesn't sort like you think it does
Anurag Lahon
@anuraglahon16
May 06 2016 03:30
@Chrono79 how do u think i can improve it
Diego Mayer
@Chrono79
May 06 2016 03:30
VultureBetrayer mention someone (or more than one) and say thank you
VultureBetrayer
@VultureBetrayer
May 06 2016 03:30
@ndburrus thanks
CamperBot
@camperbot
May 06 2016 03:30
vulturebetrayer sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
VultureBetrayer
@VultureBetrayer
May 06 2016 03:30
@Chrono79 thanks
CamperBot
@camperbot
May 06 2016 03:30
vulturebetrayer sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
Diego Mayer
@Chrono79
May 06 2016 03:31
@anuraglahon16 you have to use a sort function that sort numbers, read Array.sort docs on MDN
and you have to change the condition of the if where you're returning
Norvin Burrus
@ndburrus
May 06 2016 03:31
:sparkles: @VultureBetrayer
VultureBetrayer
@VultureBetrayer
May 06 2016 03:31
I would have probably just dropped it today and tried to figure it out tomorrow if you hadn't had the patience to help me
Tim
@codemymind
May 06 2016 03:31
thank you for the help today @bitgrower
CamperBot
@camperbot
May 06 2016 03:31
codemymind sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star2: 1033 | @bitgrower |http://www.freecodecamp.com/bitgrower
Islam Ibakaev
@dagman
May 06 2016 03:32
@anuraglahon16 `arr.sort()` works correctly only with strings (if i am not mistaken). so u should provide a condition in order for it work correctly for arrays
Jeff
@meankraken
May 06 2016 03:32
@VultureBetrayer I tried clearing cache and cookies, still having same issue lol
VultureBetrayer
@VultureBetrayer
May 06 2016 03:32
Anurag Lahon
@anuraglahon16
May 06 2016 03:32
i use arr.sort and place in a variable @Chrono79
Jeff
@meankraken
May 06 2016 03:32
@VultureBetrayer it's happening on almost every codepen I go to, for example this one http://codepen.io/pixelass/pen/eZbQZP
Anurag Lahon
@anuraglahon16
May 06 2016 03:33
@dagman of it applies only on string?
VultureBetrayer
@VultureBetrayer
May 06 2016 03:33
Islam Ibakaev
@dagman
May 06 2016 03:33
@anuraglahon16 not
VultureBetrayer
@VultureBetrayer
May 06 2016 03:33
you broke code pen
Anurag Lahon
@anuraglahon16
May 06 2016 03:33
@dagman it applies here also
Diego Mayer
@Chrono79
May 06 2016 03:33

@anuraglahon16

To compare numbers instead of strings, the compare function can simply subtract b from a. The following function will sort the array ascending:

``````function compareNumbers(a, b) {
return a - b;
}``````
Norvin Burrus
@ndburrus
May 06 2016 03:33
@VultureBetrayer ...that's funny - broke codepen.... :) they are going to be mad in the morning!
Jeff
@meankraken
May 06 2016 03:33
@VultureBetrayer wait you're saying its happening to you too?
VultureBetrayer
@VultureBetrayer
May 06 2016 03:33
must be a bug on the site as I'm getting the same issue
Anurag Lahon
@anuraglahon16
May 06 2016 03:34
@dagman var scores = [1, 10, 2, 21];
scores.sort(); // [1, 10, 2, 21]
// Watch out that 10 comes before 2,
Jeff
@meankraken
May 06 2016 03:34
@VultureBetrayer errr that's not good that codepen's broken, but I'm reallllly relieved its not just me, lol. Thanks for taking the time!
CamperBot
@camperbot
May 06 2016 03:34
meankraken sends brownie points to @vulturebetrayer :sparkles: :thumbsup: :sparkles:
VultureBetrayer
@VultureBetrayer
May 06 2016 03:34
yes, probably something you are doing is causing it to crash when attempting to load in a particular type of window
Islam Ibakaev
@dagman
May 06 2016 03:34
@anuraglahon16 that what i try to say to u
Anurag Lahon
@anuraglahon16
May 06 2016 03:34
@Chrono79 like that also it sorts out
VultureBetrayer
@VultureBetrayer
May 06 2016 03:34
sure thing, that's weird, but it can happen on sites that render stuff for yuo like that
Anurag Lahon
@anuraglahon16
May 06 2016 03:35
@dagman it sorts for arrays also
VultureBetrayer
@VultureBetrayer
May 06 2016 03:35
did you notice your pen works in the chat here?
I'd actually send that off to them to look at
Islam Ibakaev
@dagman
May 06 2016 03:36
@anuraglahon16 works incorrectly without compare function. Are u hear me? :worried:
@anuraglahon16 push into array, sort array, get index of num
Jeff
@meankraken
May 06 2016 03:38
@VultureBetrayer Just noticed a trend.. any pen that uses a precompiler like babel or SCSS has the issue, pens with vanilla JS and CSS don't have it
VultureBetrayer
@VultureBetrayer
May 06 2016 03:38
question about strict equality, is this what they use to test data sets when building database applications? for instance would you use a strict equality operator to determine if something was both the correct value as well as if it's a text(100) etc?
Anurag Lahon
@anuraglahon16
May 06 2016 03:39
@dagman ohh....vl try dat
Rhjoo
@Rhjoo
May 06 2016 03:39
Having trouble with "Stand in Line" test in JavaScript module. I keep getting TypeError: arr.shift is not a function.
function nextInLine(arr, item) {
arr = arr.push(item);
newArr = arr.shift();
return newArr; // Change this line
VultureBetrayer
@VultureBetrayer
May 06 2016 03:39
ohhhh Rhjoo. .. .I just got through that
Lurk
@reformedRattlesnake
May 06 2016 03:39
For javascript it is about type coercion - not sure if that's what you're asking
Rhjoo
@Rhjoo
May 06 2016 03:40
How did you get past that @VultureBetrayer?
VultureBetrayer
@VultureBetrayer
May 06 2016 03:40
@Rhjoo I don't want to just give the answer, but maybe I can help you as i was helped
Rhjoo
@Rhjoo
May 06 2016 03:40
Sure. Any help would be appreciated!
Puvendran Pillay
@puven12
May 06 2016 03:41
is the .map funstion similar to a loop function?
Diego Mayer
@Chrono79
May 06 2016 03:41
@puven12 yes
Puvendran Pillay
@puven12
May 06 2016 03:41
thanks dude!
VultureBetrayer
@VultureBetrayer
May 06 2016 03:41
@Rhjoo first read the function and look at the two parameteres
@Rhjoo can you post your parameters here?
also to post code, do ``` (shift + enter) then paste your code, then hit (ctrl + enter) to send
Rhjoo
@Rhjoo
May 06 2016 03:42
Like this?
function nextInLine(arr, item) { }
ok let me try. Sorry new here.
Diego Mayer
@Chrono79
May 06 2016 03:43
help format
CamperBot
@camperbot
May 06 2016 03:43

## :point_right: code formatting [wiki]

### Multi line Code

```js ⇦ Type 3 backticks and then press `[shift + enter ⏎]` (type js or html or css)

``````<paste your code here>,
then press [shift + enter ⏎]``````

``` ⇦ Type 3 backticks, then press `[enter ⏎]`

### Single line Code

This an inline ``<paste code here>`` code formatting with a single backtick(`) at start and end around the `code`.

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

VultureBetrayer
@VultureBetrayer
May 06 2016 03:43
that's your function and your parameters as well as the function declaration
so, first, what is your function?
(this is what was screwing me up)
Rhjoo
@Rhjoo
May 06 2016 03:44

'''

function nextInLine(arr, item) {
arr = arr.push(item);
newArr = arr.shift();
return newArr; // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));

CamperBot
@camperbot
May 06 2016 03:44
Rhjoo
@Rhjoo
May 06 2016 03:46
``````
function nextInLine(arr, item) {
arr = arr.push(item);
newArr = arr.shift();
return newArr;  // Change this line
}

// Test Setup
var testArr = [1,2,3,4,5];

// Display Code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log("After: " + JSON.stringify(testArr));``````
VultureBetrayer
@VultureBetrayer
May 06 2016 03:46
back tickes are in the upper left by the little ~
Norvin Burrus
@ndburrus
May 06 2016 03:46
@Rhjoo review the syntax... :)
``````SyntaxEDIT
arr.push(element1, ..., elementN)``````
VultureBetrayer
@VultureBetrayer
May 06 2016 03:46
right, so first
once you understand the function and elements its going to make more sense
Rhjoo
@Rhjoo
May 06 2016 03:46
``````function nextInLine(arr, item) {
arr = arr.push(item);
newArr = arr.shift();
return newArr;  // Change this line
}``````
Diego Mayer
@Chrono79
May 06 2016 03:47
@Rhjoo your problem is this, array.push(); returns nothing
so, nothing.shift() is not a function
Rhjoo
@Rhjoo
May 06 2016 03:47
Oh ok, let me try something
VultureBetrayer
@VultureBetrayer
May 06 2016 03:47
I think he's getting confused similarly to how I was (except he's thinking the newArr is the issue, (which I tried before asking questions)
Daniel
@profoundhub
May 06 2016 03:47
Hi Everyone, I am new to this chatroom
Diego Mayer
@Chrono79
May 06 2016 03:48
Hi
VultureBetrayer
@VultureBetrayer
May 06 2016 03:48
@profoundhub hello
Lurk
@reformedRattlesnake
May 06 2016 03:48
@Chrono79 Bah, I wanted to see @VultureBetrayer walk through the one he almost gave up on :P
Anurag Lahon
@anuraglahon16
May 06 2016 03:48

function getIndexToIns(arr, num) {
// Find my place in this sorted array.
arr.push(num);
arr.sort();
for(i = 0; i < arr.length; i++){
if(arr[i] === num){
return i;
}
}
}

getIndexToIns([40, 60], 50);
hey it doesn't pass the test for me? @dagman

Rhjoo
@Rhjoo
May 06 2016 03:48
Got it! Worked and passed!
VultureBetrayer
@VultureBetrayer
May 06 2016 03:48
there ya go
Anurag Lahon
@anuraglahon16
May 06 2016 03:48
@Chrono79
Rhjoo
@Rhjoo
May 06 2016 03:49
Thanks a lot @VultureBetrayer !
CamperBot
@camperbot
May 06 2016 03:49
rhjoo sends brownie points to @vulturebetrayer :sparkles: :thumbsup: :sparkles:
Norvin Burrus
@ndburrus
May 06 2016 03:49
@Rhjoo check the logic.... you have an array (arr) which is passed into the function. the code then assigns a push/ed item from that array to the (entire?) array (itself). ??
VultureBetrayer
@VultureBetrayer
May 06 2016 03:49
you did better than me, took me an hour and a half lol
Diego Mayer
@Chrono79
May 06 2016 03:50
@anuraglahon16 you have to use the function I posted before to make the sort work
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
using sort() will never work (well, not never, but not in this case)
Rhjoo
@Rhjoo
May 06 2016 03:50
I didn't realize that arr.push only adds it and does not create a new array
Daniel
@profoundhub
May 06 2016 03:50
@VultureBetrayer how's it going?
Lurk
@reformedRattlesnake
May 06 2016 03:50

@anuraglahon16

To compare numbers instead of strings, the compare function can simply subtract b from a. The following function will sort the array ascending:

``````function compareNumbers(a, b) {
return a - b;
}``````
VultureBetrayer
@VultureBetrayer
May 06 2016 03:50
@profoundhub coding and chatting
Lurk
@reformedRattlesnake
May 06 2016 03:50
To quote @Chrono79 from earlier...
Anurag Lahon
@anuraglahon16
May 06 2016 03:51
@reformedRattlesnake @Chrono79 thanx got it
CamperBot
@camperbot
May 06 2016 03:51
anuraglahon16 sends brownie points to @reformedrattlesnake and @chrono79 :sparkles: :thumbsup: :sparkles:
Norvin Burrus
@ndburrus
May 06 2016 03:53
@VultureBetrayer you make a good tutor!! :fire:
Diego Mayer
@Chrono79
May 06 2016 03:53
'nite everyone
Daniel
@profoundhub
May 06 2016 03:54
looks fun, I am looking for a good tutorial site for understanding arrays and algorithms, any suggestions?
Norvin Burrus
@ndburrus
May 06 2016 03:55
@profoundhub Welcome!!! :)
VultureBetrayer
@VultureBetrayer
May 06 2016 03:56
@ndburrus that's nice of you to say, however I'm still a nubcake :P
Norvin Burrus
@ndburrus
May 06 2016 03:56
@VultureBetrayer in the grand scheme of things, aren't we all?
Lurk
@reformedRattlesnake
May 06 2016 03:57
I just joined last night, so...
VultureBetrayer
@VultureBetrayer
May 06 2016 03:57
@profoundhub have you seen this site: http://www.java-made-easy.com/java-arrays.html
Daniel
@profoundhub
May 06 2016 03:59
@VultureBetrayer thanks, I 'll check it out... it that for Java AND Javascript? or are the concepts the same?
CamperBot
@camperbot
May 06 2016 04:00
profoundhub sends brownie points to @vulturebetrayer :sparkles: :thumbsup: :sparkles:
VultureBetrayer
@VultureBetrayer
May 06 2016 04:00
@ndburrus that's a fact, you should have seen me this week trying to set up mySQL and PHP on a win 2008 r2 server
I gained new hatred for MS
GitResumeCoding
@GitResumeCoding
May 06 2016 04:03
looking for some help on the profile lookup challenge, can someone peek at my solution and point me in the right direction. I am pretty sure that I am doing some huge error
Mike Haslam
@Ongomobile
May 06 2016 04:04
Hello Campers I am trying to learn how to increment/decrement a stepper with javascript then save quantity * a value to variable , then total all to get total value. Here is a codepen I have been trying stuff http://codepen.io/Ongomobile/pen/XdyBgv?editors=1000
VultureBetrayer
@VultureBetrayer
May 06 2016 04:06
@Ongomobile your buttons are incrementing and decrementing the top value even if I do the bottom buttons
Angelo Ryndon
@AIRyndon
May 06 2016 04:06
``````function chunkArrayInGroups(arr, size) {
// Break it up.
var newArray = [];
var item = [];
while(arr.length >= size)
{
item = arr.splice(0,size);
newArray.push(item);
//chunkArrayInGroups(arr,size);
}
if(arr.length !== 0)
{
item = arr.splice(0,arr.length);
newArray.push(item);
}

return newArray;
}
//chunkArrayInGroups(testArr);

chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6],3);``````
Halo Guys! This one passess the Chunky Monkey Bonfire. I'm just curious of better implementations. Please post it here as I want to learn a lot of ways of doing things. Thanks! :smile:
Marvin Andara
@babycakez
May 06 2016 04:06
Hello guys! Could someone help me with the seek and destroy problem from the basic algorithm scripting. I finished everything except this one. If you found some good examples of using array.filter() I would appreciate it if you could share.
Mike Haslam
@Ongomobile
May 06 2016 04:08
@VultureBetrayer Thanks I realize that just kept it in so something was working, I need help with understand how to write a better function no id's hard coded in function etc
CamperBot
@camperbot
May 06 2016 04:08
ongomobile sends brownie points to @vulturebetrayer :sparkles: :thumbsup: :sparkles:
Lurk
@reformedRattlesnake
May 06 2016 04:08
@AIRyndon If instead of splicing, you just push a slice, you could eliminate some things...
@babycakez Are you having trouble with a specific part of it?
Christina
@cgraham74
May 06 2016 04:09
help sum all primes
CamperBot
@camperbot
May 06 2016 04:09

# Explanation:

The explanation for this problem is very simple. You will generate a list of prime numbers up to the number you are given as a parameter. Then you need to add them all up and return that value. The tricky part is on generating the list of prime numbers. I suggest you find a code or a good math algorithm that you can turn into code.

Sean DiSanti
May 06 2016 04:09
@AIRyndon here's mine http://bit.ly/1rw7eh1
VultureBetrayer
@VultureBetrayer
May 06 2016 04:09
@profoundhub sorry missed your question, javascript and java work similarly, but do have differences, however the basics are pretty much the same
Angelo Ryndon
@AIRyndon
May 06 2016 04:11
@badc0ded Hey bro, that code doesn't pass yet. Brb later, just finishing work
Sean DiSanti
May 06 2016 04:12
lol, must have messed with it at some point since solving it
one sec will take a look
Lurk
@reformedRattlesnake
May 06 2016 04:12
@AIRyndon You could use one for loop and no conditional, that way...
Marvin Andara
@babycakez
May 06 2016 04:13
@reformedRattlesnake Im going to give it another go real quick.
Sean DiSanti
May 06 2016 04:16
oh duh
they changed the function name since i did it
@AIRyndon http://bit.ly/21CuN4m the same with the function name updated
d wilder
@alhazen1
May 06 2016 04:24
@badc0ded Huh! Sure enough. I wonder why the function name change - weird
Sean DiSanti
May 06 2016 04:25
a lot has changed
Chuck Redd
@cred3
May 06 2016 04:28
Hi guys. Can anyone help with this,
DamianMitchell
@DamianMitchell
May 06 2016 04:29
ok....I've worked on this for about 4 hours and didn't get it: the lesson is "Generate Random Whole Numbers within a Range", can someone help me
Sean DiSanti
May 06 2016 04:29
sure, what's up Damian?
d wilder
@alhazen1
May 06 2016 04:30
@AIRyndon This was not my first stab at the problem. I kept minimizing and this is what I came up with
``````function chunkArrayInGroups(arr, size) {
var temp = [];

while(arr.length){
temp.push(arr.splice(0, size));
}
return temp;
}``````
Mick
@MickBass
May 06 2016 04:32
why are these so friggin hard to do........
Sean DiSanti
May 06 2016 04:32
nice
Lurk
@reformedRattlesnake
May 06 2016 04:32
@alhazen1 :+1:
DamianMitchell
@DamianMitchell
May 06 2016 04:32
the lessons is asking for a return number that's greater than or equal to myMin, and is less than or equal to myMax: I wrote this, return Math.floor(Math.random() * (myRandom >= myMin && myRandom <= myMax));
Lurk
@reformedRattlesnake
May 06 2016 04:33
@MickBass Could you be more specific? Hard is good! Challenge makes the learning and all that. hehe
Anurag Lahon
@anuraglahon16
May 06 2016 04:33
What is API ?
Mick
@MickBass
May 06 2016 04:33
clearer instructions would be better
DamianMitchell
@DamianMitchell
May 06 2016 04:35
@badc0ded the lessons is asking for a return number that's greater than or equal to myMin, and is less than or equal to myMax: I wrote this, return Math.floor(Math.random() * (myRandom >= myMin && myRandom <= myMax))
Sean DiSanti
May 06 2016 04:35
wiki formatting
CamperBot
@camperbot
May 06 2016 04:35

## :point_right: code formatting [wiki]

### Multi line Code

```js ⇦ Type 3 backticks and then press `[shift + enter ⏎]` (type js or html or css)

``````<paste your code here>,
then press [shift + enter ⏎]``````

``` ⇦ Type 3 backticks, then press `[enter ⏎]`

### Single line Code

This an inline ``<paste code here>`` code formatting with a single backtick(`) at start and end around the `code`.

See also: ☛ How to type Backticks | ☯ Compose Mode | ❄ Gitter Formatting Basics

Lurk
@reformedRattlesnake
May 06 2016 04:36
There's always going to be things you have to do without instructions, heh. Think of it as honing search-fu as well as coding...
Sean DiSanti
May 06 2016 04:37
very true @reformedRattlesnake
DamianMitchell
@DamianMitchell
May 06 2016 04:37

return Math.floor(Math.random() * (myRandom >= myMin && myRandom <= myMax));
// Change this line

``                }``

// Change these values to test your function
var myRandom = randomRange(5, 15);

Mick
@MickBass
May 06 2016 04:37
Im stuck on Stand in line.. and I feel like I havn't learnt a thing
Sean DiSanti
May 06 2016 04:38
ok, one second
Richard Andrews
@Whiplash5057
May 06 2016 04:38
Guys need help ....I want to the information of the weather of the next four days ...I'm using http://openweathermap.org/forecast5
Lurk
@reformedRattlesnake
May 06 2016 04:38
We've gotten a few of those, today. Is there a specific thing you're stuck on, or something you think should work but doesn't? @MickBass
Mick
@MickBass
May 06 2016 04:39
i have no idea what im supposed to do
Richard Andrews
@Whiplash5057
May 06 2016 04:40
But I don't know how to get the response for the next five days ...I cannot see The information for the weather for the next five days ...I can only see information of the next day
Mick
@MickBass
May 06 2016 04:40
this isnt teaching me Javascript at all !
Sean DiSanti
May 06 2016 04:40
@DamianMitchell math.Random returns a number between 0 and 1
96street
@96street
May 06 2016 04:40
Confirm the ending
Sean DiSanti
May 06 2016 04:40
floor of any number between 0 and 1 is going to return 0
96street
@96street
May 06 2016 04:40
``````
function confirmEnding(str, target) {

var end = str.length;
var start = end - target.length;

if((str.search(target) === true) && (str.substr(start, end) === true)) {

return true;}

else {return false;}

}

confirmEnding("Bastian", "n");``````
what am I doing wrong here?
Chuck Redd
@cred3
May 06 2016 04:40
Can someone help me with this,
Sean DiSanti
May 06 2016 04:41
oh, duh, i see the issue
you're multiplying your math.random() times a boolean
(myRandom >= myMin && myRandom <= myMax)
should be (max - min)) + min
Chris Cullen
@123xylem
May 06 2016 04:42
``````var arr =[["There is a natural aristocracy among men. The grounds of this are virtue and talents."," Thomas Jefferson (1743-1826)"],["All our words from loose using have lost their edge.",
"Ernest Hemingway (1898-1961)"],["God couldn't be everywhere, so he created mothers.",
"Jewish proverb"],

var newarr=[];
for(i=0;i<arr.length;i++){
newarr.push(arr[i]);
}
return newarr;``````
Sean DiSanti
May 06 2016 04:42
DamianMitchell
@DamianMitchell
May 06 2016 04:42
ok...if I read the instruction right, it calls for a boolean
Chris Cullen
@123xylem
May 06 2016 04:42
Can some1 tell me how to return this in codepen?
Sean DiSanti
May 06 2016 04:43
Math.floor(Math.random() * (max - min)) + min
what is the challenge name?
Lurk
@reformedRattlesnake
May 06 2016 04:43
@MickBass You still gotta put the self in self-learning, hehe. Have you played around with it or are you stuck at the instructions? It gives you a function that wants two arguments - an array, and an item, right? But all it does by default is just return item.
DamianMitchell
@DamianMitchell
May 06 2016 04:43
that's the sample equations
Marvin Andara
@babycakez
May 06 2016 04:43
If the helpful links suggest Array.filter(), does that mean that I should use it? Like is that the point of the challenge? I can do the problem just not using array.filter();
Sean DiSanti
May 06 2016 04:44
what is the name of the challenge so i can look up the instructions
Lurk
@reformedRattlesnake
May 06 2016 04:44
I think you should just do what you are able, and if it functions then if you like you can use the hints to think about how else you might have done it, you know? I don't know that it's necessarily always the better solution, but it could be simpler.
DamianMitchell
@DamianMitchell
May 06 2016 04:44
generate Random whole Numbers within a range
Sean DiSanti
May 06 2016 04:45
@babycakez if it suggests a function, that means one way could use the function, but there are always multiple solutions
help generate random whole numbers within a range
CamperBot
@camperbot
May 06 2016 04:45

# Generate Random Whole Numbers within a Range

We can use a certain mathematical expression to get a random number between two numbers.

`Math.floor(Math.random() * (max - min + 1)) + min`

Sean DiSanti
May 06 2016 04:45
it wants you to return a number, not a boolean
whoops wrong one
one sec
that was from random fractions
Marvin Andara
@babycakez
May 06 2016 04:46
@badc0ded It is the seek and destroy in basic algorithm scripting
Sean DiSanti
May 06 2016 04:47
i did not use filter for seek and destroy
DamianMitchell
@DamianMitchell
May 06 2016 04:47
@babycakez except it ask for greater than or equal to
Sean DiSanti
May 06 2016 04:47
wait, yes i did
right, but when you use <= and >= you turn it into a boolean
to be evaluated to true or false
if you implement the formula from the example
Math.floor(Math.random() * (max - min + 1)) + min
it will do what you want
DamianMitchell
@DamianMitchell
May 06 2016 04:49
and not worry to much on what it ask for?
Sean DiSanti
May 06 2016 04:50
that formula is the formula to return what it is asking for, you just have to set the min and max
96street
@96street
May 06 2016 04:53
Confirm the ending
``````
function confirmEnding(str, target) {

var end = str.length;
var start = end - target.length;

if((str.search(target) === true) && (str.substr(start - 1, end - 1) === target)) {

return true;
}

else {return false;}

}

confirmEnding("Bastian", "n");``````
why isn't this working?
Kyle W Pilkinton
May 06 2016 04:54
hey guys im new to js and i cant figure out why this isnt passing the test on free code camp
myMusic 1 = [
{
"artist": "psy",
"title": "gangnam_style",
"release_year": 2013,
"formats": [
"mp3",
"disc",
"live"]
}
];
Sean DiSanti
May 06 2016 04:54
what test is failing? @tadake same question @96street
96street
@96street
May 06 2016 04:55
it's not returning true for str's that end in target
Chris Cullen
@123xylem
May 06 2016 04:55
Im trying to seperate my nested array into Name and Quote Variables. So I did for loops that look at the sub array 0 and 1 and label them name or quote... Am I anywhere near on this?
``````var arr =[["There is a natural aristocracy among men. The grounds of this are virtue and talents."," Thomas Jefferson (1743-1826)"],["All our words from loose using have lost their edge.",
"Ernest Hemingway (1898-1961)"]
var quote= "";
var newarr=[];
for(i=0;i<arr.length;i++){

for(j=0;j<arr[i].length;j++){var name="";
arr[i][j][0]= quote;
arr[i][j][1]= name;
}}
console.log(name);``````
Sean DiSanti
May 06 2016 04:56
looking in console real quick @96street
one sec
Thomas G.
@CaptainMurphey
May 06 2016 04:57
hey guys if i have a function inside another function and the inner function has a return, it will only pop me out of the inner funtion right ?
Sean DiSanti
May 06 2016 04:58
end shouldn't be the length should it?
since the last character's index isn't the length
it's the length minus one
Kyle W Pilkinton
May 06 2016 04:58
the Introducing JavaScript Object Notation JSON one. im supposed to make a new album to add onto the current one @badc0ded
Sean DiSanti
May 06 2016 04:59
and what test is coming back red @tadake
Kyle W Pilkinton
May 06 2016 04:59
myMusic1 should have at least 4 properties
myMusic1 should contain an artist property which is a string
myMusic1 should contain a title property which is a string
myMusic1 should contain a release_year property which is a number
myMusic1 should contain a formats property which is an array
formats should be an array of strings with at least two elements
96street
@96street
May 06 2016 05:00
that's why I did (str.substr(start - 1, end - 1) in my if statement
Sean DiSanti
May 06 2016 05:00
you're assigning an array to myMusic1, but it looks like it should be an object
that's just the first thing that jumps out at me
try removing the square braces
and go from there
Kyle W Pilkinton
May 06 2016 05:02
that worked thanks! @badc0ded the first example had square braces so i assumed that was mandatory! lol im new at js
CamperBot
@camperbot
May 06 2016 05:02
Sean DiSanti
May 06 2016 05:02
no problem, i'm glad i could hlep
help
CamperBot
@camperbot
May 06 2016 05:02

### Basic Commands:

• `find TOPIC` find all entries about topic. ex: `find js`
• `wiki TOPIC` show contents of topic page
• `thanks @username` send brownie points to another user
• `about @username` shows info on that user
• `Algorithm BONFIRENAME` info on a Algorithm

:speech_balloon: meet CamperBot in this room!

Sean DiSanti
May 06 2016 05:03
i'm looking at yours again @96street but you can move that -1 to the end assignment instead of adding it after the fact to both
96street
@96street
May 06 2016 05:03
true ill do that
this is what i've got now:
``````function confirmEnding(str, target) {

var end = str.length - 1;
var start = end - target.length;

if((str.search(target) === true) && (str.substr(start, end) === target)) {

return true;
}

else {return false;}

}

confirmEnding("Bastian", "n");``````
Sean DiSanti
May 06 2016 05:06
try this and see if it clears it up
``````function confirmEnding(str, target) {

var end = str.length -1;
var start = end - target.length;
console.log('end: ',end,', start: ',start);
console.log('first test:', str.search(target),', substring:',str.substr(start, end));
if((str.search(target) === true) && (str.substr(start, end) === target)) {

return true;
}

else {return false;}

}

confirmEnding("Bastian", "n");``````
just threw in some debugging code so you can see the values
96street
@96street
May 06 2016 05:08
what did you change and why?
what's the purpose of this: console.log('end: ',end,', start: ',start);
Sean DiSanti
May 06 2016 05:08
i added console logs so that this output would show you why it's returning false
96street
@96street
May 06 2016 05:09
oh right
hmm
Sean DiSanti
May 06 2016 05:10
the substring being compared to the target is not matching because start to end is greater than the length of the target
96street
@96street
May 06 2016 05:11
how is that?
Sean DiSanti
May 06 2016 05:11
you're checking a 2 character string against a 1 character string
an is longer than n
96street
@96street
May 06 2016 05:11
Shouldn't the '-1' counter that?
Sean DiSanti
May 06 2016 05:13
if the length of the target is 1, start and end should be the same, right?
96street
@96street
May 06 2016 05:13
yeah
Sean DiSanti
May 06 2016 05:14
i'm trying to lead you to figuring it out without just giving you the answer
96street
@96street
May 06 2016 05:14
is is only not working because the length is 1?
yeah thinking now
Sean DiSanti
May 06 2016 05:14
try it with a 2 character target
i'd say keep the debugging output while you're playing with it
whenever you get unexpected results it's a good idea to add output that shows what you expect and what you're getting
96street
@96street
May 06 2016 05:15
as in the console.log like you did?
Sean DiSanti
May 06 2016 05:15
it saves us from our assumptions
yes, though i only showed what we are getting, not what we are expecting
but in this case we were definitely expecting the substring to be 'n'
and we see that it's not
96street
@96street
May 06 2016 05:17
2 character target isn't wokring aswell
Sean DiSanti
May 06 2016 05:19
i have to get going shortly for an early morning tomorrow, but don't want to leave you stranded on this one if you're having issues
if you want to work backwards from my solution, i can show it to you
96street
@96street
May 06 2016 05:20
yes
Sean DiSanti
May 06 2016 05:20
oh, i see what it is i think
you're giving it start and end
96street
@96street
May 06 2016 05:20
Sean DiSanti
May 06 2016 05:20
not start and length
Omid
@omidqayoumi
May 06 2016 05:21
that feel when you're about to ask a question, then you take 5 more mins to review the code and you figure out the bugs :feelsgood:
Sean DiSanti
May 06 2016 05:21
substring's parameters that it wants are start and length
96street
@96street
May 06 2016 05:21
right
Sean DiSanti
May 06 2016 05:22
you're telling it start and end
96street
@96street
May 06 2016 05:22
that gives me something, i'll work off that
Sean DiSanti
May 06 2016 05:22
Brian
@sludge256
May 06 2016 05:22
@omidqayoumi Sounds like Rubber Duck Debugging :P
96street
@96street
May 06 2016 05:23
``str.substr(start, start + target.length)``
doesn't work either
Sean DiSanti
May 06 2016 05:23
right, start + length is still going to be greater than length
May 06 2016 05:24
`/^[-+]?(?:\.[0-9]+|(?:0|[1-9][0-9]*)(?:\.[0-9]*)?)\$/` this whole regexp is needed to match just a base10 number (just a trivia)
Omid
@omidqayoumi
May 06 2016 05:24
@sludge256 that's exactly what I did :laughing: , just looked up the story behind that
96street
@96street
May 06 2016 05:24
``str.substr(start, target.length)``
Omid
@omidqayoumi
May 06 2016 05:24
I should buy a rubber duck
96street
@96street
May 06 2016 05:24
not working
wait thats no right
Sean DiSanti
May 06 2016 05:25
what does your full code look like now?
look at the output
96street
@96street
May 06 2016 05:25
``````
function confirmEnding(str, target) {

var end = str.length - 1;
var start = end - target.length;

if((str.search(target) === true) && (str.substr(start, target.length) === target)) {

return true;
}

else {return false;}

}

confirmEnding("qqqqme", "me");``````
Sean DiSanti
May 06 2016 05:26
the -1 on end now is getting in your way i think
96street
@96street
May 06 2016 05:26
target.length should be start start + target.length instead should it
Omid
@omidqayoumi
May 06 2016 05:26
oh I'm doing that challenge right now too
Sean DiSanti
May 06 2016 05:26
or that
96street
@96street
May 06 2016 05:27
how else do you cope with the counting from 0 on the substring?
Sean DiSanti
May 06 2016 05:27
throw the console logs back in to see what you're getting
i promise they help
96street
@96street
May 06 2016 05:28
``````
function confirmEnding(str, target) {

var end = str.length - 1;
var start = end - target.length;
console.log('end: ',end,', start: ',start);
console.log('first test:', str.search(target),', substring:',str.substr(start, end));

if((str.search(target) === true) && (str.substr(start, target.length) === target)) {

return true;
}

else {return false;}

}

confirmEnding("qqqqme", "me");``````
this is just printing 'false'
not the console.logs
Sean DiSanti
May 06 2016 05:28
Lurk
@reformedRattlesnake
May 06 2016 05:29
Try running it in your console, then. It helps to see in this case substring is 'qme' for example...
Sean DiSanti
May 06 2016 05:29
first test is returning '6'
which while it's truthy, is not strict true
96street
@96street
May 06 2016 05:29
Sean DiSanti
May 06 2016 05:30
-1 i believe
``````function confirmEnding(str, target) {

var end = str.length;
var start = end - target.length;
console.log('end: ',end,', start: ',start);
console.log('first test:', str.search(target),', substring:',str.substr(start, target.length));
if((str.search(target) > -1) && (str.substr(start, target.length) === target)) {

return true;
}

else {return false;}

}

confirmEnding("Bastian", "n");``````
Frank XC
@tenkdayz
May 06 2016 05:32

what is the use of this? anyone..

``````(function(){
//some code
})();``````

I've seen this a few times now..

96street
@96street
May 06 2016 05:33
works :)
CamperBot
@camperbot
May 06 2016 05:33
96street sends brownie points to @badc0ded :sparkles: :thumbsup: :sparkles:
Sean DiSanti
May 06 2016 05:33
no problem, i'm glad i could help
96street
@96street
May 06 2016 05:33
-1 is the same as true?
Sean DiSanti
May 06 2016 05:33
my solution is pretty similar just without the extra variables etc http://bit.ly/1SQVK2h
Daniel Godigna
@DGAcode
May 06 2016 05:34
hello need some help here " Returning Boolean Values from Functions "
Sean DiSanti
May 06 2016 05:34
so by confirming that the response is greater than -1, we confirm that the substring is found
Daniel Godigna
@DGAcode
May 06 2016 05:34
``````function isLess(a, b) {
// Fix this code
switch (a < b) {
case a<b:
return true;
default:
return false;
}
}

// Change these values to test
isLess(10, 15);``````
96street
@96street
May 06 2016 05:34
false = -1?
true > -1?
Daniel Godigna
@DGAcode
May 06 2016 05:35
need to return isLess (15,10) false
Sean DiSanti
May 06 2016 05:35
typically 0 is falsy, not -1
but that function returns -1 instead of false
because the target could be found at index 0
96street
@96street
May 06 2016 05:36
right
rphares
@rphares
May 06 2016 05:36
dont need any kind of switch, @33hawk ....
Sean DiSanti
May 06 2016 05:36
@33hawk just return the evaluation
Daniel Godigna
@DGAcode
May 06 2016 05:36
well I know but I have to
rphares
@rphares
May 06 2016 05:36
check out the example again-- see how they used equality with just one line?
no, you dont need an if/else OR a switch,
they just want the one line,
Sean DiSanti
May 06 2016 05:36
if you return the comparison, it will be evaluated to true or false by the receiver
Daniel Godigna
@DGAcode
May 06 2016 05:37
ok
thanks
thank you what I am thinking
@rphares thanks
CamperBot
@camperbot
May 06 2016 05:37
33hawk sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star2: 4362 | @rphares |http://www.freecodecamp.com/rphares
rphares
@rphares
May 06 2016 05:37
Everyone does it-- your solution is much more logical than many first tries :blush: Happy coding!
Anytime~
Sean DiSanti
May 06 2016 05:38
ok well i have to call it a night
up in 4 hours blah
have a good one everybody
Daniel Godigna
@DGAcode
May 06 2016 05:38
@rphares thanks again
CamperBot
@camperbot
May 06 2016 05:38
33hawk sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:warning: 33hawk already gave rphares points
rphares
@rphares
May 06 2016 05:38
G'night, @badc0ded ~ (and ty for the assist with the one above :blush: )
CamperBot
@camperbot
May 06 2016 05:38
rphares sends brownie points to @badc0ded :sparkles: :thumbsup: :sparkles:
Sean DiSanti
May 06 2016 05:38
no problem, i'm glad i could help
and thanks for the point @rphares
rphares
@rphares
May 06 2016 05:39
Was deserved! Night :blush:
Sean DiSanti
May 06 2016 05:39
and thanks for the point @rphares
CamperBot
@camperbot
May 06 2016 05:39
badc0ded sends brownie points to @rphares :sparkles: :thumbsup: :sparkles:
:star2: 4363 | @rphares |http://www.freecodecamp.com/rphares
rphares
@rphares
May 06 2016 05:39
(dont need one back-- I'm super brownie fat!)
Sean DiSanti
May 06 2016 05:39
forgot that it doesn't point on edits
rphares
@rphares
May 06 2016 05:39
heh, no worries, rest well!
Sean DiSanti
May 06 2016 05:39
i've only recently been able to get them
with my name being a number
rphares
@rphares
May 06 2016 05:40
well, you'll end up big quickly, helping out a lot tends to do that~ :blush:
Sean DiSanti
May 06 2016 05:40
i do miss being able to make jokes about why i wasn't getting them, but that's ok
yeah, i do it for the practice more than the brownies
then and now
ok, really leaving, i could totally hang out in here all night again
rphares
@rphares
May 06 2016 05:41
indeed, i started cause there was no cbot in this room, so no one knew that the help button led people here, heh
yep! Night!
Daniel
@profoundhub
May 06 2016 05:41
wow, @badc0ded & @rphares, you two are pretty active tonight :)
rphares
@rphares
May 06 2016 05:42
lol, nah (nice new pic, btw, @profoundhub !) just got on and shall pop around rooms as usual :blush:
Sean DiSanti
May 06 2016 05:42
no i'm not i'm gone
96street
@96street
May 06 2016 05:42
function confirmEnding(str, target)
str.substr(start, target.length)
confirmEnding("Bastian", "n");
wouldn't the substring = str.substr(6, 0) ? @badc0ded
Sean DiSanti
May 06 2016 05:42
you're giving it length 0
96street
@96street
May 06 2016 05:42
the only thing i don't get is target.length here
Sean DiSanti
May 06 2016 05:42
so you're asking for a 0 length string
the only 0 lenght string is ""
96street
@96street
May 06 2016 05:43
but str.subtr refers to positions not length
Sean DiSanti
May 06 2016 05:43
first argument is starting position
96street
@96street
May 06 2016 05:43
6 being th estarting position 0 being the ned position
Sean DiSanti
May 06 2016 05:43
second is length
substr doesn't want end
it wants length
96street
@96street
May 06 2016 05:43
ohhhh that's why
cheers
Sean DiSanti
May 06 2016 05:43
yep
no problem
Daniel
@profoundhub
May 06 2016 05:43
well i'm trying to work thru all the javascript challenges and thought this group is more focused on JS
96street
@96street
May 06 2016 05:43
str.substr(start, start + target.length) works aswell which is weird
Sean DiSanti
May 06 2016 05:44
really really really leaving now
96street
@96street
May 06 2016 05:44
haha
Sean DiSanti