These are chat archives for FreeCodeCamp/HelpJavaScript

27th
Apr 2016
Tyler
@tylergross
Apr 27 2016 00:00
@developingMichael what are you returning?
sorry wrong person
@starvingartist4 what are you returning?
Reid Delahunt
@starvingartist4
Apr 27 2016 00:00
I'm trying to return the longest word length
wait, wrong prompt haha
trying to titlecase everything
Tyler
@tylergross
Apr 27 2016 00:01
@starvingartist4 what does your function return at the moment ?
in the console it probably returns an array right?
your code looks good so far the only thing i see missing is where you join it back together into a string
Stephen James
@sjames1958gm
Apr 27 2016 00:02
@starvingartist4 you are not modifying the strings. toUpperCase returns the modified string, so your strings are not changed
@starvingartist4 Strings are immutable, unlike arrays. The inner loop can be done with slice and toLowerCase
Stephen James
@sjames1958gm
Apr 27 2016 00:07
@starvingartist4 strArray[i] = strArray[i].slice(0,1).toUpperCase() + strArray[i].slice(1).toLowerCase();
Randall Wyatt
@RandallWy
Apr 27 2016 00:08
needing help with the word blanks assignment
frsRaza
@frsRaza
Apr 27 2016 00:09
    <section id="information">
      <div class="container">
        <div class="row">
          <div class="col-lg-12 text-center">
            <h2>Countdown to our Wedding Date!</h2>
            <div id="countdown">

            <script type="text/javascript">
            var ringer = {
              //countdown_to: "10/31/2014",
              countdown_to: "11/24/2016",
              rings: {
                'DAYS': {
                  s: 86400000, // mseconds in a day,
                  max: 365
                },
                'HOURS': {
                  s: 3600000, // mseconds per hour,
                  max: 24
                },
                'MINUTES': {
                  s: 60000, // mseconds per minute
                  max: 60
                },
                'SECONDS': {
                  s: 1000,
                  max: 60
                },
              },
              r_count: 4,
              r_spacing: 10, // px
              r_size: 100, // px
              r_thickness: 2, // px
              update_interval: 11, // ms

              init: function(){

                $r = ringer;
                $r.cvs = document.createElement('canvas');

                $r.size = {
                  w: ($r.r_size + $r.r_thickness) * $r.r_count + ($r.r_spacing*($r.r_count-1)),
                  h: ($r.r_size + $r.r_thickness)
                };

                $r.cvs.setAttribute('width',$r.size.w);
                $r.cvs.setAttribute('height',$r.size.h);
                $r.ctx = $r.cvs.getContext('2d');
                $(document.body).append($r.cvs);
                $r.cvs = $($r.cvs);
                $r.ctx.textAlign = 'center';
                $r.actual_size = $r.r_size + $r.r_thickness;
                $r.countdown_to_time = new Date($r.countdown_to).getTime();
                $r.cvs.css({ width: $r.size.w+"px", height: $r.size.h+"px" });
                $r.go();
              },
              ctx: null,
              go: function(){
                var idx=0;

                $r.time = (new Date().getTime()) - $r.countdown_to_time;


                for(var r_key in $r.rings) $r.unit(idx++,r_key,$r.rings[r_key]);

                setTimeout($r.go,$r.update_interval);
              },
              unit: function(idx,label,ring) {
                var x,y, value, ring_secs = ring.s;
                value = parseFloat($r.time/ring_secs);
                $r.time-=Math.round(parseInt(value)) * ring_secs;
                value = Math.abs(value);

                x = ($r.r_size*.5 + $r.r_thickness*.5);
                x +=+(idx*($r.r_size+$r.r_spacing+$r.r_thickness));
                y = $r.r_size*.5;
                y += $r.r_thickness*.5;

                // calculate arc end angle
                var degrees = 270-(value / ring.max) * 360.0;
                var endAngle = degrees * (Math.PI / 180);

                $r.ctx.save();

                $r.ctx.translate(x,y);
                $r.ctx.clearRect($r.actual_size*-0.5,$r.actual_size*-0.5,$r.actual_size,$r.actual_size);

                // first circle
                $r.ctx.strokeStyle = "rgba(128,128,128,0.2)";
                $r.ctx.beginPath();
                $r.ctx.arc(0,0,$r.r_size/2,0,2 * Math.PI, 2);
                $r.ctx.lineWidth =$r.r_thickness;
                $r.ctx.stroke();

                // second circle
                $r.ctx.strokeStyle = "rgba(253, 128, 1, 0.9)";
                $r.ctx.beginPath();
                $r.ctx.arc(0,0,$r.r_size/2,3*Math.PI/2,0,endAngle, 1);
                $r.ctx.lineWidth =$r.r_thickness;
                $r.ctx.stroke();

                // label
                $r.ctx.fillStyle = "#ffffff";

                $r.ctx.font = '12px Helvetica';
                $r.ctx.fillText(label, 0, 23);
                $r.ctx.fillText(label, 0, 23);

                $r.ctx.font = 'bold 40px Helvetica';
                $r.ctx.fillText(Math.floor(value), 0, 10);

                $r.ctx.restore();
              }
            }

            ringer.init();
            </script>
            </div>

          </div>
Need help. The javascript countdown is showing at the bottom of the body element and I need them to show in this specific section/div. How do I do that?
Faktura179
@Faktura179
Apr 27 2016 00:09
In word blanks you have to concatenate strings
daiwik
@daiwik
Apr 27 2016 00:11
anyone know how to add new paragraphs using javascript on webpage. Number of paragraph depends on random number
Randall Wyatt
@RandallWy
Apr 27 2016 00:12
elaborate @Faktura179 i tried to do it the way i was taught in my JS classes in school but its not working
Moisés Man
@moigithub
Apr 27 2016 00:12
@frsRaza $(document.body).append($r.cvs);
u adding that to document.body...
probably u wanna put inside this element <div id="countdown">
Stephen James
@sjames1958gm
Apr 27 2016 00:12
@daiwik Just use a for loop and use Jquery or document.createElement to create the elements
Faktura179
@Faktura179
Apr 27 2016 00:13
str+=str1+" "+str2;
Randall Wyatt
@RandallWy
Apr 27 2016 00:13
ok
thanks @Faktura179
CamperBot
@camperbot
Apr 27 2016 00:13
randallwy sends brownie points to @faktura179 :sparkles: :thumbsup: :sparkles:
:star: 297 | @faktura179 | http://www.freecodecamp.com/faktura179
frsRaza
@frsRaza
Apr 27 2016 00:14
@moigithub when I edit that javascript, it deletes the countdown out of the page. The javascript is currently in that div. I've tried to $(document.getElementById("countdown")).append($r.cvs); but that also didn't work.
Moisés Man
@moigithub
Apr 27 2016 00:15
u non need to use getElementbyid.. if u using jquery $(document.body)
$("#countdown").append($r.cvs); @frsRaza
Randall Wyatt
@RandallWy
Apr 27 2016 00:16
@Faktura179 tried that. didnt work

function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
var result = "";
// Your code below this line
var a = "dog";
var b = "big";
var c = "ran";
var d = "quickly";
var e = "cat";
var f = "little";
var g = "hit";
var h = "slowly";

var srt1 = a +" "+b+" "+c+" "+d;
// Your code above this line
return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");

Faktura179
@Faktura179
Apr 27 2016 00:17
@RandallWy += is used when you append
If you dont want to append use just =
Moisés Man
@moigithub
Apr 27 2016 00:17
@RandallWy u need to work with the argumetns/variables provided
check the function header
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
frsRaza
@frsRaza
Apr 27 2016 00:17
@moigithub didn't seem to work
Faktura179
@Faktura179
Apr 27 2016 00:18
Also i belive order of vrs is important
Randall Wyatt
@RandallWy
Apr 27 2016 00:18
i tried that @moigithub but it errored out
Moisés Man
@moigithub
Apr 27 2016 00:18
@RandallWy post ur code.. with "that",, u dont need to create new variables
hjernefrys
@hjernefrys
Apr 27 2016 00:18
can someone take a look at my random quotes codepen (slightly NSFW language as the quotes are from rick and morty) the problem is that it's not escaping ´and " properly, but I can't seem to fix it: https://codepen.io/icenburg/pen/vGaKzb
Stephen James
@sjames1958gm
Apr 27 2016 00:19
@RandallWy set result to the built up string - use the parameters not a, b, c, d - get rid of all the hardcoded strings
Faktura179
@Faktura179
Apr 27 2016 00:20
@RandallWy dont create new variabeles and just use the ones passed to the function
Randall Wyatt
@RandallWy
Apr 27 2016 00:20
ok I am getting 3 different answers. Can a moderator only reply.
Stephen James
@sjames1958gm
Apr 27 2016 00:20
@hjernefrys You don't have to escape ' when inside ""
Randall Wyatt
@RandallWy
Apr 27 2016 00:21
still lost.
Faktura179
@Faktura179
Apr 27 2016 00:21
@RandallWy plus you return empty string
Stephen James
@sjames1958gm
Apr 27 2016 00:21
@hjernefrys I am not sure what you mean = it looks good (well except red background makes it hard to read)
hjernefrys
@hjernefrys
Apr 27 2016 00:22
well I have to change the look, just trying to get the functionality correctly now
the problem is when I try to tweet a quote, it breaks the sentence on '
Stephen James
@sjames1958gm
Apr 27 2016 00:23
@hjernefrys ah
Frank XC
@tenkdayz
Apr 27 2016 00:23
@hjernefrys no need to escape the ' inside "
Moisés Man
@moigithub
Apr 27 2016 00:24
Faktura179
@Faktura179
Apr 27 2016 00:24
result =myAdjective +" "+ myNoun (...) @RandallWy
Chase Webb
@jerrybaggin
Apr 27 2016 00:24
function findLongestWord(str) {
  var strArray = str.split("");

  if(str.length > str ){
       for(var i = 0; i > str; i++){

    }
     }
  return str.length;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
Could I get a push in the right direction? I feel like im getting close, but im still sorta lost on my if statement.
im returning the the whole length of the string currently 44.
Stephen James
@sjames1958gm
Apr 27 2016 00:27
@hjernefrys Reverse the quotes in the <a construction - '<a href="https://twitter.com/intent/tweet?text=' + quotes[numberToUse] + '"'
frsRaza
@frsRaza
Apr 27 2016 00:28
@moigithub I did that .. countdown rings disappeared. Is it possibly my css might be over riding any of it?
Islam Ibakaev
@dagman
Apr 27 2016 00:28
@jerrybaggin you should change to this var strArray = str.split(" ");
Moisés Man
@moigithub
Apr 27 2016 00:28
@frsRaza Thats using jquery.. (u need to add the library ).... without jquery... sec.. googling
Faktura179
@Faktura179
Apr 27 2016 00:28
@jerrybaggin. You are comparing string with integer in if statement
Moisés Man
@moigithub
Apr 27 2016 00:29
@frsRaza
//$("#countdown").append($r.cvs); <-- remove
instead.. use this
document.getElementById("countdown").appendChild($r.cvs);
frsRaza
@frsRaza
Apr 27 2016 00:30
still didn't fix... @moigithub
Moisés Man
@moigithub
Apr 27 2016 00:31
@frsRaza well if u check the codepen link.. its working... and its inside that div#countdown.. if u cant see... probably its like u said.. some of ur css
@frsRaza maybe u have white lines.. on a white background ??? everything "white"... u wont be able to see
hjernefrys
@hjernefrys
Apr 27 2016 00:32
thanks very much @sjames1958gm it worked!
CamperBot
@camperbot
Apr 27 2016 00:32
hjernefrys sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 819 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Apr 27 2016 00:32
@hjernefrys :+1:
frsRaza
@frsRaza
Apr 27 2016 00:33
@moigithub i'm using a bootstrap carousel as the background (even though that's another bug that's not working currently)
Moisés Man
@moigithub
Apr 27 2016 00:34
@frsRaza some bootstrap elements... requires u to add the javascript bootstrap library too
and bootstrap also depends on jquery.. so u need to add jquery library too
D.Mills
@millsdee74
Apr 27 2016 00:34
thanks @CaroleAnneHannon for your help with Checkpoint: Stand in Line
CamperBot
@camperbot
Apr 27 2016 00:34
millsdee74 sends brownie points to @caroleannehannon :sparkles: :thumbsup: :sparkles:
:star: 839 | @caroleannehannon | http://www.freecodecamp.com/caroleannehannon
Randall Wyatt
@RandallWy
Apr 27 2016 00:36
Is my == operator in the right spot?

// Setup
function testEqual(myVal) {
if (myVal == 12) { // Change this line
return "Equal";
}
return "Not Equal";
}

// Change this value to test
testEqual(12);

Moisés Man
@moigithub
Apr 27 2016 00:36
@RandallWy yes.. thats correct
Randall Wyatt
@RandallWy
Apr 27 2016 00:36
hmm. its not letting me progess. :(
Moisés Man
@moigithub
Apr 27 2016 00:36
but.. u have == (2) equal this test values
and === (3) deep equality this test values and data type
Randall Wyatt
@RandallWy
Apr 27 2016 00:37
its only the ==
Moisés Man
@moigithub
Apr 27 2016 00:37
refresh the browser maybe ?
Randall Wyatt
@RandallWy
Apr 27 2016 00:38
i have and reset the code
Abby
@s0uth
Apr 27 2016 00:38
thanks @leftynaut for your help with Checkpoint: Profile Lookup
CamperBot
@camperbot
Apr 27 2016 00:38
s0uth sends brownie points to @leftynaut :sparkles: :thumbsup: :sparkles:
:star: 492 | @leftynaut | http://www.freecodecamp.com/leftynaut
Randall Wyatt
@RandallWy
Apr 27 2016 00:38
what could be wrong @moigithub
Moisés Man
@moigithub
Apr 27 2016 00:39
whats the exercise name ?
or post the link
Randall Wyatt
@RandallWy
Apr 27 2016 00:39
Comparison with the Equality Operator
Moisés Man
@moigithub
Apr 27 2016 00:40
@RandallWy ok.. this is the original code
// Setup
function testEqual(val) {
  if (val) { // Change this line
    return "Equal";
  }
  return "Not Equal";
}

// Change this value to test
testEqual(10);
@RandallWy u should ONLY change this line
if (val) { // Change this line
do NOT rename the variables
Randall Wyatt
@RandallWy
Apr 27 2016 00:40
srsly? lol
Amor Kumar
@itsamoreh
Apr 27 2016 00:46

Hey everyone, I'm stuck on "Profile Lookup" just wondering if anyone can help me.

function lookUpProfile(firstName, prop){
// Only change code below this line
  for (var x = 0; x < contacts.length; x++) {
    if (! contacts[x][firstName]) {
      return "No such contact";
    }
    if (! contacts[x][prop]) {
      return "No such property";
    }
  }
// Only change code above this line
}

That's my lookUpProfile function. "No such contact" gets returned when it should but "No such property" does not get returned. Does anyone know why?

Robert-Jan
@Zorba68
Apr 27 2016 00:50
@itsamoreh use: contacts[x].hasOwnProperty(prop)
@itsamoreh you can't reference a property with [prop] if it doesn't exist, so you have to use that method
Chase Webb
@jerrybaggin
Apr 27 2016 00:53
function findLongestWord(str) {
  var strArray = str.split(" ");
  var final = 0;

   for(var i = 0; i < strArray.length; i++){
       if( final < strArray.length[i]){
         final = strArray.length[i];
       }

   } return final;
}

findLongestWord("The quick brown fox jumped over the lazy dog");
I feel like im almost there now, but im var final ends up zero still? I take it through the for loop and assign it a value?
Amor Kumar
@itsamoreh
Apr 27 2016 00:53
@Zorba68 so now I have it like this:
for (var x = 0; x < contacts.length; x++) {
    if (! contacts[x][firstName]) {
      return "No such contact";
    }
    if (! contacts[x].hasOwnProperty(prop)) {
      return "No such property";
    }
  }
but that still doesn't work.
Moisés Man
@moigithub
Apr 27 2016 00:56
@jerrybaggin if( final < strArray.length[i]){
length is not an array or string.. so u cant use [i] (the index) on it...
if( final < strArray[i].length){ <--- probably ?
Chase Webb
@jerrybaggin
Apr 27 2016 00:57
@moigithub haha good find. didn't even realize I did that! thank you
CamperBot
@camperbot
Apr 27 2016 00:57
jerrybaggin sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star: 1016 | @moigithub | http://www.freecodecamp.com/moigithub
Robert-Jan
@Zorba68
Apr 27 2016 00:57
@itsamoreh you also need to return the right values when name/property exist
@itsamoreh and the ifs need to be nested
Amor Kumar
@itsamoreh
Apr 27 2016 00:59
haha I was going step by step and didn't get to that part yet but shouldn't the code I have fulfill this?
"Akira", "address" should return "No such property"
Moisés Man
@moigithub
Apr 27 2016 01:00
@itsamoreh follow line by line.. what u suppose ur code is doing ??? use some values
Joseph
@revisualize
Apr 27 2016 01:01
@itsamoreh you should use Pythontutor.com and you'll see why your for loop only loops once.
bitgrower
@bitgrower
Apr 27 2016 01:02
^^^^ what @revisualize said ... once you execute a return statement, not only are you exiting the loop, you are exiting the function ...
quiet ...
bitgrower
@bitgrower
Apr 27 2016 01:14
test
Charlotte N.
@clnquacky
Apr 27 2016 01:16
@clnquacky
Still struggling with getting this search field to clear after a search is submitted so a second+ search can be done..http://codepen.io/clnquacky/pen/zqLKVQ
I have thought about trying a function.. But not sure how to set it up.. I have tried a form of .reset, I have tried resetting the variable to 0. But I think I am missing something simple. .. Any suggestions.
bitgrower
@bitgrower
Apr 27 2016 01:17
why not have a line of code which clears the field on submit ?
Amor Kumar
@itsamoreh
Apr 27 2016 01:21
thanks @Zorba68 and @revisualize
CamperBot
@camperbot
Apr 27 2016 01:21
itsamoreh sends brownie points to @zorba68 and @revisualize :sparkles: :thumbsup: :sparkles:
:star: 288 | @zorba68 | http://www.freecodecamp.com/zorba68
:star: 985 | @revisualize | http://www.freecodecamp.com/revisualize
Charlotte N.
@clnquacky
Apr 27 2016 01:21
That is what I am thinking. but not sure if it would go in html section or java..
maybe as part of input (onsubmit=" "); ??
daiwik
@daiwik
Apr 27 2016 01:22
@clnquacky how long did it take you to make that
Charlotte N.
@clnquacky
Apr 27 2016 01:23
a while.. Been working on it for several days.
eduwin7
@eduwin7
Apr 27 2016 01:24
need help
myArray.unshift("Paul", 35);
bitgrower
@bitgrower
Apr 27 2016 01:24
yeah, I would think you could have an onClick function, @clnquacky ?
eduwin7
@eduwin7
Apr 27 2016 01:25
can anyone help me please
bitgrower
@bitgrower
Apr 27 2016 01:25
what are you trying to do @eduwin7 ?
Master Builder
@McGowanC
Apr 27 2016 01:25
@clnquacky I feel like your final thing could just change the value back to nothing like $( "input" ).prop( "value", "" );
eduwin7
@eduwin7
Apr 27 2016 01:25
myArray should now have [["Paul", 35], ["dog", 3]].
bitgrower
@bitgrower
Apr 27 2016 01:26
@eduwin7 -- we need more information ... like the entire code, what challenge you are working on ...
eduwin7
@eduwin7
Apr 27 2016 01:26
manipulating Arrays using unshift

// Example
var ourArray = ["Stimpson", "J", "cat"];
ourArray.shift(); // ourArray now equals ["J", "cat"]
ourArray.unshift("Happy");
// ourArray now equals ["Happy", "J", "cat"]

// Setup
var myArray = [["John", 23], ["dog", 3]];
myArray.shift();

// Only change code below this line.

myArray.unshift("Paul", 35);

Charlotte N.
@clnquacky
Apr 27 2016 01:27
@bitgrower @wcrm I will try both.... Not at the same time obviously :)
bitgrower
@bitgrower
Apr 27 2016 01:27
This message was deleted
henrywashere
@henrywashere
Apr 27 2016 01:28

can anyone help me with this exercise?
Instructions
Write a switch statement which tests val and sets answer for the following conditions:
1 - "alpha"
2 - "beta"
3 - "gamma"
4 - "delta"

this is what i have so far but it wouldnt go through

function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch (answer) {

    case 1:
      val = Alpha;
      break;
      }
eduwin7
@eduwin7
Apr 27 2016 01:28
@bitgrower ?
Charlotte N.
@clnquacky
Apr 27 2016 01:29
@eduwin7 you need to shift each value out, then unshift the new values in.
Bruce Young
@mutantspore
Apr 27 2016 01:29
This message was deleted
henrywashere
@henrywashere
Apr 27 2016 01:30
ok lemme try that
Bruce Young
@mutantspore
Apr 27 2016 01:30
@henrywashere no
bitgrower
@bitgrower
Apr 27 2016 01:30
@eduwin7 -- in this particular example, you are unshifting an array into a 2 dimensional array ...
Bruce Young
@mutantspore
Apr 27 2016 01:30
its val for the case
and then what i had
bitgrower
@bitgrower
Apr 27 2016 01:31
you are unshifting 2 different elements .. you need to unshift just 1 ... which is the array ...
"Add ["Paul",35] to the beginning of the myArray variable using unshift()." ....
Bruce Young
@mutantspore
Apr 27 2016 01:31
@henrywashere you are switching on val and then assigning something to answer
bitgrower
@bitgrower
Apr 27 2016 01:32
so, you have it almost correct, except that what you have in parentheses has to be an array .. as this is: ["Paul",35]
henrywashere
@henrywashere
Apr 27 2016 01:32
so its like
case val:
      answer = 'Alpha';
      break;
Bruce Young
@mutantspore
Apr 27 2016 01:33
yes but keep track of the text case.. upper/lower
’alpha’
henrywashere
@henrywashere
Apr 27 2016 01:33
oh right
eduwin7
@eduwin7
Apr 27 2016 01:33
@bitgrower yes. thats what i have
henrywashere
@henrywashere
Apr 27 2016 01:34
huh it didnt work lol
bitgrower
@bitgrower
Apr 27 2016 01:34
no, you don't, @eduwin7 you have this: ("Paul", 35) .. that's not the same thing!
Bruce Young
@mutantspore
Apr 27 2016 01:34
@henrywashere what is it actually called
eduwin7
@eduwin7
Apr 27 2016 01:34
shoot me now
henrywashere
@henrywashere
Apr 27 2016 01:35
shall i post the whole code??
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch (answer) {

    case val:
      answer = 'alpha';
      break;

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

// Change this value to test
caseInSwitch(1);
Robert-Jan
@Zorba68
Apr 27 2016 01:35
@henrywashere you need switch (val)
bitgrower
@bitgrower
Apr 27 2016 01:35
don't sweat it ... code is VERY detailed ... and those kinds of mistakes are legion ... :)
Tyler
@tylergross
Apr 27 2016 01:35
is there an operator for an if function that says IF A or B but not both A and B?
Bruce Young
@mutantspore
Apr 27 2016 01:35
@henrywashere yes i said switch on val
henrywashere
@henrywashere
Apr 27 2016 01:36
oooh
ok that worked ty
thanks @Zorba68 @mutantspore
CamperBot
@camperbot
Apr 27 2016 01:36
henrywashere sends brownie points to @zorba68 and @mutantspore :sparkles: :thumbsup: :sparkles:
:star: 289 | @zorba68 | http://www.freecodecamp.com/zorba68
:star: 1463 | @mutantspore | http://www.freecodecamp.com/mutantspore
Tyler
@tylergross
Apr 27 2016 01:37
if(oppA[z][0] === playerA ||  oppA[z][1] === playerA){
            if(oppA[z][0] === 0 || oppA[z][1] === 0){


            }
        }
using that right now was wondering if there was an easier way to put if A or B but not both
bitgrower
@bitgrower
Apr 27 2016 01:38
@tylergross -- you are talking about an exclusive OR ... and I don't believe there is, you'll just have to create it ...
Tyler
@tylergross
Apr 27 2016 01:38
@bitgrower ah yes that's it i know i've used one before in PHP wasn't sure if js had one. thanks
CamperBot
@camperbot
Apr 27 2016 01:38
tylergross sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 1015 | @bitgrower | http://www.freecodecamp.com/bitgrower
Aaron Preston
@AaronPreston
Apr 27 2016 01:38
Array.prototype.slice.call(arguments);
Can someone explain to me why we put the .prototype in there? To my understanding, JavaScript isn't exactly object oriented, so it's called prototyping, but that's all I really understand about that concept.
bitgrower
@bitgrower
Apr 27 2016 01:39
does php have one, @tylergross ? I don't remember any more ...
Tyler
@tylergross
Apr 27 2016 01:39
@bitgrower yes if($a XOR b)
bitgrower
@bitgrower
Apr 27 2016 01:39
ah ... I just found this, @tylergross -- XOR
oops -- I didn't read far enough: Unfortunately, JavaScript does not have a logical XOR operator
this is the page I was reading: http://www.howtocreate.co.uk/xor.html
Tyler
@tylergross
Apr 27 2016 01:40
think i stumbled upon the same page
Robert-Jan
@Zorba68
Apr 27 2016 01:40
@tylergross only bitwise I guess: ^
bitgrower
@bitgrower
Apr 27 2016 01:41
hahahahahaha ... yeah, exclusive ORs are magical ...
Tyler
@tylergross
Apr 27 2016 01:41
yeah oh well would be nice in some cases just a bit more coding to do
bitgrower
@bitgrower
Apr 27 2016 01:44
yeah ... I can kinda see why they wouldn't choose to do so -- there's far more truthy stuff than falsy in JS -- so would be subject to coding errors -- it's kinda more useful in a bit context (imnsho) ...
Brendon
@Balvamar
Apr 27 2016 01:46
This message was deleted
sorry
This message was deleted
This message was deleted
bitgrower
@bitgrower
Apr 27 2016 01:47
you can erase or modify your messages @Balvamar
Bobby McDonald
@BobbyMcWho
Apr 27 2016 01:47
I feel like I was doing super well right up until I hit this quote machine challenge
and now I've lost my motivation
Brendon
@Balvamar
Apr 27 2016 01:47
@bitgrower thanks
CamperBot
@camperbot
Apr 27 2016 01:47
balvamar sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 1016 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Apr 27 2016 01:47
yw, @Balvamar
Brendon
@Balvamar
Apr 27 2016 01:48
This message was deleted
bitgrower @bitgrower decides to experiment ...
bitgrower
@bitgrower
Apr 27 2016 01:49
This message was deleted
CamperBot
@camperbot
Apr 27 2016 01:49
:star: 254 | @balvamar | http://www.freecodecamp.com/balvamar
bitgrower sends brownie points to @balvamar :sparkles: :thumbsup: :sparkles:
bitgrower
@bitgrower
Apr 27 2016 01:49
thanks @Balvamar
CamperBot
@camperbot
Apr 27 2016 01:49
bitgrower sends brownie points to @balvamar :sparkles: :thumbsup: :sparkles:
:warning: bitgrower already gave balvamar points
bitgrower
@bitgrower
Apr 27 2016 01:50
heh ... thanks are permanently given, I guess !
about @Balvamar
CamperBot
@camperbot
Apr 27 2016 01:50
:star: 254 | @balvamar | http://www.freecodecamp.com/balvamar
Kevin Galang
@kgalang
Apr 27 2016 01:50
function destroyer(arr) {
function check(num) {
  return arr[0] != num;
}
  return arr.filter(check);
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);
can someone tell me how to call the entire subarray? instead of arr[0] being 1, I expected arr[0] to be [1,2,3,1,2,3]
bitgrower
@bitgrower
Apr 27 2016 01:50
oh boy seek & destroy, one of my favorites ...
@kgalang -- the "trick" to this particular challenge is to read about argument objects ..
you are being passed multiple arguments ... but only the first one is actually named ... so you have to use the arguments object to access the rest ...
Kevin Galang
@kgalang
Apr 27 2016 01:51
@bitgrower I appreciate it lol that's all the help I need for now
@bitgrower thank you
CamperBot
@camperbot
Apr 27 2016 01:51
kgalang sends brownie points to @bitgrower :sparkles: :thumbsup: :sparkles:
:star: 1017 | @bitgrower | http://www.freecodecamp.com/bitgrower
bitgrower
@bitgrower
Apr 27 2016 01:52
I spent many hours working that out, @kgalang ... when I figured out what was going on, I was very proud of myself ... LOL
I couldn't figure out why arr = [1,2,3,1,2,3] ...
Brendon
@Balvamar
Apr 27 2016 01:53
how do i format my code?
Bobby McDonald
@BobbyMcWho
Apr 27 2016 01:54
@Balvamar ``` js shift+enter [code] shift+enter ```
This message was deleted
Coy Sanders
@coymeetsworld
Apr 27 2016 01:54
help format
CamperBot
@camperbot
Apr 27 2016 01:54

: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

:pencil: read more about code formatting on the FCC Wiki

Galiante
@Galiante
Apr 27 2016 01:55
This message was deleted
function palindrome(str) {
  // Good luck!
  str = str.replace (/\W/g,'').toLowerCase();
  return (str == str.split('').reverse().join(''));
}

palindrome("0_0 (: /-\ :) 0-0");
I can't solve this palindrome. I need remove all non-alphanumeric characters (punctuation, spaces and symbols) and I don't know how
96street
@96street
Apr 27 2016 01:58

Defined a variable

  var $orders = $('#orders');

Then I console.log($orders); and it says '$orders is not defined'. Why?

Brendon
@Balvamar
Apr 27 2016 01:59
function pali(str) {
  var nStr = str.toLowerCase();
  var word = '';
  var alph = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];

  for (var i = 0; i < nStr.length; i++) {
    for (var j = 0; j < alph.length; j++) {
      if (nStr[i] === alph[j]) {
        word += nStr[i];
      }
    }
  }
  var rev = word.split('').reverse().join('');
  if (word === rev) {
    return rev;
  } else {
    return false;
  }

}
console.log(pali("1 eye for of 1 eye."));
all test pass in this challenge, except the one at the bottom, not sure why
return there should be true, not rev ;)
Stephen James
@sjames1958gm
Apr 27 2016 02:01
@Balvamar Numbers are not supposed to be excluded.
Brendon
@Balvamar
Apr 27 2016 02:01
correct, but the code removes the numbers and puctuation.
my appologies, NOT excluded
Robert-Jan
@Zorba68
Apr 27 2016 02:02
@Balvamar @Galiante if you use a regular expression it's not so hard
Bobby McDonald
@BobbyMcWho
Apr 27 2016 02:02
you're overcomplicating things
Brendon
@Balvamar
Apr 27 2016 02:02
did try regular expression, but don't really get it.
will try again.
Robert-Jan
@Zorba68
Apr 27 2016 02:03
modifiedString = modifiedString.replace(/[^a-z0-9]/g, "");
that will remove anything non-alphanumerical
Brendon
@Balvamar
Apr 27 2016 02:04
@Zorba68 thank-you, just have not really used it before.
CamperBot
@camperbot
Apr 27 2016 02:04
balvamar sends brownie points to @zorba68 :sparkles: :thumbsup: :sparkles:
:star: 290 | @zorba68 | http://www.freecodecamp.com/zorba68
henrywashere
@henrywashere
Apr 27 2016 02:06
this wont go through for some reason:
Instructions
Write a switch statement which tests val and sets answer for the following conditions:
1 - "alpha"
2 - "beta"
3 - "gamma"
4 - "delta"
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch (val) {

    case val:
      answer = 'alpha';
      break;

    case val:
      answer = "beta";
      break;

    case val:
      answer = "gamma";
      break;

    case val:
      answer = "delta";
      break;

      }   
  // Only change code above this line  
  return answer;  
}
Dylan
@dhcodes
Apr 27 2016 02:07
@henrywashere what's the last line of the code
what's their test line say?
Robert-Jan
@Zorba68
Apr 27 2016 02:08
@henrywashere you want to test for the cases 1 to 4
Dylan
@dhcodes
Apr 27 2016 02:08
oh yeah, nvm
Dustin
@Key-Banger
Apr 27 2016 02:08
@henrywashere all of the case are testing for the same thing.
Dylan
@dhcodes
Apr 27 2016 02:08
@Zorba68 is on to it
you need to change val to numbers
Galiante
@Galiante
Apr 27 2016 02:11
@Zorba68 Yeah....now this palindrom with non-alphanumeric is okey, but now the other two are not good
henrywashere
@henrywashere
Apr 27 2016 02:11
i dont get it
change val to numbers??
Robert-Jan
@Zorba68
Apr 27 2016 02:12
@henrywashere you want to check val, for certain cases. you do that with switch (val) and then case 1: case 2: etc
Erik Maurer
@MauPow
Apr 27 2016 02:12
I need help on pulling JSON data from an API. working on the wikipedia search project. Been trying for days. I CANNOT GET IT TO WORK.
var searchTerm;

$(document).ready(function() {
  var go = $("#go").click(find);

  //Get search value and wiki API
  function find() {
    searchTerm = $("#lookUp").val();

    var url = "https://crossorigin.me/http://en.wikipedia.org/w/api.php?format=json&action=query&titles=" + searchTerm + "&prop=revisions&rvprop=content";

    console.log(url);

    $.getJSON( url, function( data ) {
  var items = [];
  $.each( data, function( key, val ) {
    items.push( "<li id='" + key + "'>" + val + "</li>" );
  });

  $( "<ul/>", {
    "class": "my-new-list",
    html: items.join( "" )
  }).appendTo( "body" );
});
}
});
This is directly copied from the jquery docs and modified with my url. IT SHOULD WORK>
WHY DOES IT NOT
I have tried with and without ?callback, with and without https://crossorigin.me
it refuses to do anytthing
henrywashere
@henrywashere
Apr 27 2016 02:13
yay i got it
Stephen James
@sjames1958gm
Apr 27 2016 02:14
@MauPow codepen link?
henrywashere
@henrywashere
Apr 27 2016 02:14
thanks @Zorba68
CamperBot
@camperbot
Apr 27 2016 02:14
:warning: henrywashere already gave zorba68 points
henrywashere sends brownie points to @zorba68 :sparkles: :thumbsup: :sparkles:
I seriously just copied it from http://api.jquery.com/jquery.getjson/ after spending hours trying to write my own code
still doesn't work
I tried using the jqHXR object, didn't work
The example from free code camp uses angularjs which I don't want to use yet
I can't even get it to log to the console just doing
```
$.getJSON(url, function(data){console.log(data);});
$.getJSON(url, function(data){console.log(data);});
Stephen James
@sjames1958gm
Apr 27 2016 02:17
@MauPow Try this in your html
@MauPow onclick="find();return false;"
Robert-Jan
@Zorba68
Apr 27 2016 02:18
@Galiante that regular expression i showed only works AFTER conversion to lower case
Erik Maurer
@MauPow
Apr 27 2016 02:19
Ok that did something... now it's making bullet points and displaying [object Object]
Stephen James
@sjames1958gm
Apr 27 2016 02:19
@MauPow Try console.log(JSON.stringify(data));
Erik Maurer
@MauPow
Apr 27 2016 02:20
{"batchcomplete":"","warnings":{"revisions":{"*":"Unrecognized value for parameter 'rvprop': content?callback"}},"query":{"normalized":[{"from":"g","to":"G"}],"pages":{"12255":{"pageid":12255,"ns":0,"title":"G","revisions":[[]]}}}}
Stephen James
@sjames1958gm
Apr 27 2016 02:21
@MauPow You searched for G?
@MauPow or g?
Erik Maurer
@MauPow
Apr 27 2016 02:21
g
Stephen James
@sjames1958gm
Apr 27 2016 02:22
@MauPow Now you are getting data back, you will need to modify your url - API info is available from wikipedia - You button was inside a form so when you clicked the form it was trying to submit the form, since it did not have anywhere to submit it it just refreshed the page. Returning false from your click handler prevents this behavior.
Galiante
@Galiante
Apr 27 2016 02:23
function palindrome(str) {
  // Good luck!
  str.toLowerCase();
  str = str.replace (/[^a-z0-9]/g,"");
  return (str == str.split('').reverse().join(''));
}

palindrome("A man, a plan, a canal. Panama");
@Zorba68 you think like that
Erik Maurer
@MauPow
Apr 27 2016 02:24
Ah ok
thanks @sjames1958gm
CamperBot
@camperbot
Apr 27 2016 02:24
maupow sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 820 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Diego Mayer
@Chrono79
Apr 27 2016 02:25
is it only me or hackerrank challenges are a lot harder than fcc?
Robert-Jan
@Zorba68
Apr 27 2016 02:25
@Galiante str.toLowerCase() does not modify str itself
Galiante
@Galiante
Apr 27 2016 02:25
thanks @Zorba68 I solved it
CamperBot
@camperbot
Apr 27 2016 02:25
galiante sends brownie points to @zorba68 :sparkles: :thumbsup: :sparkles:
:star: 291 | @zorba68 | http://www.freecodecamp.com/zorba68
Robert-Jan
@Zorba68
Apr 27 2016 02:26
cool
Galiante
@Galiante
Apr 27 2016 02:26
str = str.toLowerCase() ;
I know now :smile:
Robert-Jan
@Zorba68
Apr 27 2016 02:27
never mind!
Drew Stonebraker
@drstonebraker
Apr 27 2016 02:28
I'm on challenge 271, writing a function to remove falsy values from an array. I've already passed the challenge, but is anyone willing to look at my code? I'm just wondering if there is a more efficient way to do it or if this works as well as anything:
function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  for (var i = 0; i < arr.length; i++) {
    var testFalse = Boolean(arr[i]);
    if (testFalse === false) {
      delete arr[i];
    }
  }

  return arr.filter(function(val) {
  return val !== undefined;
});

}

bouncer([7, "ate", "", false, 9]);
Diego Mayer
@Chrono79
Apr 27 2016 02:30
@Stoney229 why are you deleting if you can filter?
Drew Stonebraker
@drstonebraker
Apr 27 2016 02:32
@Chrono79 can I filter by truthy values without first converting the value to boolean ?
Diego Mayer
@Chrono79
Apr 27 2016 02:32
@Stoney229 you can do both at the same time
function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  function notFalsy(value) {
    return Boolean(value);
  }
  return arr.filter(notFalsy);
}
Drew Stonebraker
@drstonebraker
Apr 27 2016 02:33
@Chrono79 okay. trying to think... would I need to use the thisArg parameter of the filter() method?
sorry just saw your code
@Chrono79 cool tyvm!
Diego Mayer
@Chrono79
Apr 27 2016 02:34
@Stoney229 no problem, my bad, I had to let you think it a little more
Stephen James
@sjames1958gm
Apr 27 2016 02:40
adding in arrow functions function bouncer(arr) { return arr.filter( val => val ); }
D. Omran
@domran23
Apr 27 2016 02:51
Hey all, can I get a hand with profile lookup exercise? "No such contact" is the scenario that doesn't work and it's driving me to drink lol. I think it iterates through the entire array looking for a firstName match but when it doesn't find one it goes straight to return instead of else if statement
function lookUpProfile(firstName, prop){
// Only change code below this line
  var temp;
  for(var i = 0; i < contacts.length; i++) {
    if(firstName == contacts[i].firstName) {
         if(contacts[i].hasOwnProperty(prop) === true) {
       temp = contacts[i][prop];
      } else if(firstName != contacts[i].firstName) {
         temp = "No such contact";
      } else {
        temp = "No such property";
      }
    }  
    } 
  return temp;
// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Duke", "lastName");
Coy Sanders
@coymeetsworld
Apr 27 2016 02:52

@domran23

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

will never execute

because its nested inside if firstName == contacts[i].firstName
you need to say theres no such contact after you iterate through all of them
D. Omran
@domran23
Apr 27 2016 02:53
ahh, so another if statement but outside the first one?
Coy Sanders
@coymeetsworld
Apr 27 2016 02:55
not sure what you mean
but the only way you know theres a contact w/o the first name you're looking for is if you've iterated through all of them and found nothing
D. Omran
@domran23
Apr 27 2016 02:56
I mean just get rid of the else, and make another if statement outside of firstName == contacts[i].firstName. But i'm trying it now whether that's the solution or not lol
Coy Sanders
@coymeetsworld
Apr 27 2016 02:57
basically, theres no such contact if you went through the entire contacts array and didn't find anything
so that situation would be after you exit the for loop and found no one with that name
Abdul-Samii Ajala Olalekan
@jalasem
Apr 27 2016 03:03
please what is wrong with this code?
function largestOfFour(arr) {
  // You can do this!
  var current = [];
  var biggest = 0;
  for(i = 0; i < arr.length; i++){
    for(j = 0; j < arr[i].length; j++){
      if(arr[i][j] > biggest){
        biggest = arr[i][j];
      }
    }
    current.push(biggest);
  }
  arr = current;
  return arr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

other test cases worked but this wont return [27,5,39,1001]

largestOfFour([[13, 27, 18, 26], [4, 5, 1, 3], [32, 35, 37, 39], [1000, 1001, 857, 1]])

D. Omran
@domran23
Apr 27 2016 03:04
@coymeetsworld I'm currently rewriting this to see if I understand...
Abdul-Samii Ajala Olalekan
@jalasem
Apr 27 2016 03:05
thanks @coymeetsworld
CamperBot
@camperbot
Apr 27 2016 03:05
jalasem sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star: 638 | @coymeetsworld | http://www.freecodecamp.com/coymeetsworld
Coy Sanders
@coymeetsworld
Apr 27 2016 03:07
you have your arrays out of order @jalasem
your code is working as it should
D. Omran
@domran23
Apr 27 2016 03:09
@coymeetsworld I guess I don't understand after all! This is what I have that's not working now
function lookUpProfile(firstName, prop){
// Only change code below this line
  var temp;
  for(var i = 0; i < contacts.length; i++) {
    if(firstName == contacts[i].firstName) {
         if(contacts[i].hasOwnProperty(prop) === true) {
       temp = contacts[i][prop];
      }
    }
  }
  if(firstName != contacts[i].firstName) {
    temp = "No such contact";
  } 
  if(contacts[i].hasOwnProperty(prop) === false) {
    temp = "No such property";
  }
   return temp;


      // Only change code above this line
}

// Change these values to test your function
lookUpProfile("duke", "lastName");
Coy Sanders
@coymeetsworld
Apr 27 2016 03:09
oh you need to reset biggest
@jalasem everytime you iterate through the first for loop, thats the issue
if(contacts[i].hasOwnProperty(prop) === false) {
    temp = "No such property";
  }
remove that
move that logic inside the for loop
once you find the contact, if that property exists return it, if not say no such property
D. Omran
@domran23
Apr 27 2016 03:16

ugh, I'm still not getting this...
```function lookUpProfile(firstName, prop){
// Only change code below this line
var temp;
for(var i = 0; i < contacts.length; i++) {
if(firstName == contacts[i].firstName) {
if(contacts[i].hasOwnProperty(prop) === true) {
temp = contacts[i][prop];
} else if(contacts[i].hasOwnProperty(prop) === false) {
temp = "No such property";
}
}
}
if(firstName != contacts[i].firstName) {
temp = "No such contact";
}

return temp;

  // Only change code above this line

}

// Change these values to test your function
lookUpProfile("duke", "lastName");
```

oops
function lookUpProfile(firstName, prop){
// Only change code below this line
  var temp;
  for(var i = 0; i < contacts.length; i++) {
    if(firstName == contacts[i].firstName) {
         if(contacts[i].hasOwnProperty(prop) === true) {
       temp = contacts[i][prop];
      } else if(contacts[i].hasOwnProperty(prop) === false) {
        temp = "No such property";
      }
    }
  }
  if(firstName != contacts[i].firstName) {
    temp = "No such contact";
  } 

   return temp;


      // Only change code above this line
}

// Change these values to test your function
lookUpProfile("duke", "lastName");
Catalin Scripcariu
@CatalinScr
Apr 27 2016 03:17
Help No repeats please
CamperBot
@camperbot
Apr 27 2016 03:17

:point_right: algorithm no repeats please [wiki]

Problem Explanation:

  • This task requires us to look at each possible permutation of a string. This is best done using a recursion function. Being able to build a function which collects all permutations of a string is a common interview question, so there is no shortage of tutorials out there on how to do this, in many different code languages.
  • This task can still be daunting even after watching a tutorial. You will want to send each new use of the function 3 inputs: 1. a new string (or character array) that is being built, 2. a position in your new string that's going to be filled next, and 3. an idea of what characters (more specifically positions) from the original string have yet to be used. The pseudo code will look something like this:

    ```
    var str = ???;
    perm(current position in original string, what's been used in original string, current string build thus far){
    if(current string is finished) {
    print current string;
    }else{
    for(var i = 0; i < str.length; i++) {

    if(str[i] has not been used) {
      put str[i] into the current position;
      mark str[i] as used
      perm(current position in original string, what's been used in original string, current string build thus far)
      unmark str[i] as used because another branch in the tree for i + 1 will still likely use it;
    }

    }
    }
    }
    :pencil: read more about algorithm no repeats please on the FCC Wiki

Coy Sanders
@coymeetsworld
Apr 27 2016 03:18
you can simplify @domran23
 if(contacts[i].hasOwnProperty(prop) === true) {
       temp = contacts[i][prop];
      } else if(contacts[i].hasOwnProperty(prop) === false) {
        temp = "No such property";
      }
to this
 if(contacts[i].hasOwnProperty(prop)) {
       temp = contacts[i][prop];
 } else {
   temp = "No such property";
 }
 if(firstName != contacts[i].firstName) {
    temp = "No such contact";
  }
This needs to be changed also
contacts[i] outside of the for loop will just be the last item you accessed
so it will cause issues
D. Omran
@domran23
Apr 27 2016 03:22
Ok, I simplified the prop one. Thanks! for the other, just say firstName != contacts.fistName?
Coy Sanders
@coymeetsworld
Apr 27 2016 03:25
no, basically you know the firstname doesn't exist if you went through the loop and didn't find it
Nicolas May
@hynso
Apr 27 2016 03:26
Why does my iphone not consistently/predictably play sounds in <audio> elements?
D. Omran
@domran23
Apr 27 2016 03:28
Ok so then a condition isn't even necessary? If
If it's already established there's no contact right?
Abdul-Samii Ajala Olalekan
@jalasem
Apr 27 2016 03:35
pls take a look at this and tell me what is wrong with it
xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.codecademy.com/", false);
xhr.send();


// Add your code above this line!

console.log(xhr.status);
console.log(xhr.statusText);
Nicolas May
@hynso
Apr 27 2016 03:42
@jalasem Do you need a var before xhr in xhr = new XMLHttpRequest();?
Joseph
@revisualize
Apr 27 2016 03:42
@jalasem Which lesson are you working on?
Abdul-Samii Ajala Olalekan
@jalasem
Apr 27 2016 03:44
am working myself tru codecademy's youtube api track, mixing it with my freecodecamp tracks
Kelvin-penang
@Kelvin-penang
Apr 27 2016 03:51
Hi! Morning from Malaysia. Need some help again
'''
CamperBot
@camperbot
Apr 27 2016 03:51
:bulb: to format code use backticks! ``` more info
Kelvin-penang
@Kelvin-penang
Apr 27 2016 03:51
var Car = function() {
  // this is a private variable
  var speed = 10;

  // these are public methods
  this.accelerate = function(change) {
    speed += change;
  };

  this.decelerate = function() {
    speed -= 5;
  };

  this.getSpeed = function() {
    return speed;
  };
};

var Bike = function() {

  // Only change code below this line.
var gear = 10;
  this.getGear = function(){
    return this.setGear;
  };
  this.setGear = function(){

  };
};

var myCar = new Car();

var myBike = new Bike();
I know there's something wrong with the functions down there
myBike.getGear() should return 4 after calling myBike.setGear(4).
Can anybody help?
Coy Sanders
@coymeetsworld
Apr 27 2016 03:54
you have problems w/ your functions @Kelvin-penang
getGear should be returning gear, not this.setGear. setGear is a function
and that function should change gear to the value you send to it
so myBike.setGear(4) should change the value of gear to 4
for example
D. Omran
@domran23
Apr 27 2016 03:55
@coymeetsworld I still haven't gotten it but I'm close. If I move the return statement before checking "No such contact" everything works! so it's just that last stupid part. Alas, it is late and I have to hit the sack lol. I'll try in the AM with a rested mind. Thanks!
CamperBot
@camperbot
Apr 27 2016 03:55
domran23 sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
:star: 639 | @coymeetsworld | http://www.freecodecamp.com/coymeetsworld
Kelvin-penang
@Kelvin-penang
Apr 27 2016 03:55
@coymeetsworld so I just change getgear to gear and thats it?
Coy Sanders
@coymeetsworld
Apr 27 2016 03:56
no, also everything else I said @Kelvin-penang
np @domran23 gl
just remember when you exit the for loop you don't need to look at contacts anymore
Kelvin-penang
@Kelvin-penang
Apr 27 2016 03:57
var Car = function() {
  // this is a private variable
  var speed = 10;

  // these are public methods
  this.accelerate = function(change) {
    speed += change;
  };

  this.decelerate = function() {
    speed -= 5;
  };

  this.getSpeed = function() {
    return speed;
  };
};

var Bike = function() {

  // Only change code below this line.
var gear=this.setGear;
  this.getGear = function(){
    return gear;
  };
  this.setGear = function(){


  };
};

var myCar = new Car();

var myBike = new Bike();
D. Omran
@domran23
Apr 27 2016 03:57
Well I tried just temp = "No such contact" but it didn't like that either lol
Kelvin-penang
@Kelvin-penang
Apr 27 2016 03:57
like this? still doesn't work
Coy Sanders
@coymeetsworld
Apr 27 2016 03:57
don't set gear to this.setGear
also you haven't done anything w/ the setGear function yet
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 27 2016 04:03
can anyone help me with "profile lookup"? im kinda stuck with the code...
https://www.freecodecamp.com/challenges/profile-lookup#?solution=%2F%2FSetup%0Avar%20contacts%20%3D%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Akira%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Laine%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220543236543%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Pizza%22%2C%20%22Coding%22%2C%20%22Brownie%20Points%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Harry%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Potter%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220994372684%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Hogwarts%22%2C%20%22Magic%22%2C%20%22Hagrid%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Sherlock%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Holmes%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%220487345643%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Intriguing%20Cases%22%2C%20%22Violin%22%5D%0A%20%20%20%20%7D%2C%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22firstName%22%3A%20%22Kristian%22%2C%0A%20%20%20%20%20%20%20%20%22lastName%22%3A%20%22Vos%22%2C%0A%20%20%20%20%20%20%20%20%22number%22%3A%20%22unknown%22%2C%0A%20%20%20%20%20%20%20%20%22likes%22%3A%20%5B%22Javascript%22%2C%20%22Gaming%22%2C%20%22Foxes%22%5D%0A%20%20%20%20%7D%0A%5D%3B%0A%0A%0Afunction%20lookUpProfile(firstName%2C%20prop)%7B%0A%2F%2F%20Only%20change%20code%20below%20this%20line%0A%20%20var%20temp%3B%0A%20%20for(var%20i%20%3D%200%3B%20i%20%3C%20contacts.length%3B%20i%2B%2B)%20%7B%0A%20%20%20%20if(firstName%20%3D%3D%20contacts%5Bi%5D.firstName)%20%7B%0A%20%20%20%20%20%20%20%20%20if(contacts%5Bi%5D.hasOwnProperty(prop)%20%3D%3D%3D%20true)%20%7B%0A%20%20%20%20%20%20%20temp%20%3D%20contacts%5Bi%5D%5Bprop%5D%3B%0A%20%20%20%20%20%20%7D%20else%20if(firstName%20!%3D%20contacts%5Bi%5D.firstName)%20%7B%0A%20%20%20%20%20%20%20%20%20temp%20%3D%20%22No%20such%20contact%22%3B%0A%20%20%20%20%20%20%7D%20else%20%7B%0A%20%20%20%20%20%20%20%20temp%20%3D%20%22No%20such%20property%22%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%20%20%0A%20%20%20%20%7D%20%0A%20%20return%20temp%3B%0A%2F%2F%20Only%20change%20code%20above%20this%20line%0A%7D%0A%0A%2F%2F%20Change%20these%20values%20to%20test%20your%20function%0AlookUpProfile(%22Akira%22%2C%20%22address%22)%3B%0A%0AlookUpProfile(%22Bob%22%2C%22number%22)%3B
Kelvin-penang
@Kelvin-penang
Apr 27 2016 04:06
@coymeetsworld Thanks! :) got it
CamperBot
@camperbot
Apr 27 2016 04:06
:star: 640 | @coymeetsworld | http://www.freecodecamp.com/coymeetsworld
kelvin-penang sends brownie points to @coymeetsworld :sparkles: :thumbsup: :sparkles:
Coy Sanders
@coymeetsworld
Apr 27 2016 04:06
cool gj @Kelvin-penang
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 27 2016 04:09
@domran23 can you please help me with profile lookup code?
im stuck with this code
Catalin Scripcariu
@CatalinScr
Apr 27 2016 04:13
@PabbaShivaRamKaushil you should put else if outside the if
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 27 2016 04:16
can you please show me the code .im unable to figure it out. @CatalinScr
Catalin Scripcariu
@CatalinScr
Apr 27 2016 04:17
@PabbaShivaRamKaushil let's talk in private
Kelvin-penang
@Kelvin-penang
Apr 27 2016 04:28
var oldArray = [1,2,3,4,5];

// Only change code below this line.



var newArray =new oldArray;


for(var i=0;i<oldArray.lenght;i+=3){
  newArray[i]=oldArray[0,1,2,3,4];
}
stuck again...
kmo1
@kmo1
Apr 27 2016 04:31
var user = ['green', 'red', 'blue', 'pink', 'black', 'yellow', 'purple', 'fuchsia', 'teal', 'aqua', 'orange', 'chartreuse'];
var nIntervId;

$('html').click(function(){
  changeColor();
  goComputer();
});

function changeColor(){
  nIntervId = setInterval(flashColor, 1000);
}

function flashColor() {
  var color = getNewColors(user);
  setBackgroundColor(color, $("html"));
}

function getNewColors(array) {
  var rand = array[Math.floor(Math.random() * array.length)];
  return rand;
}

function setBackgroundColor(color, elem){
  elem.css('background-color', color);
  stopTextColor();
}

function stopTextColor() {
  clearInterval(nIntervId);
}

function goComputer() {
  changeColor();
  stopTextColor();
}
I'm trying to have this script run so that when I click the color changes twice after waiting 1 second, then stops. Once I click again it changes twice and stops, but I find that the updates won't stop
CamperBot
@camperbot
Apr 27 2016 04:31
:bulb: to format code use backticks! ``` more info
Doug
@Spazcool
Apr 27 2016 04:37
Can we copy/paste the code from the challenges into an online editor and have it run, without any modifications?
kirbyedy
@kirbyedy
Apr 27 2016 04:37
@Spazcool yes
Doug
@Spazcool
Apr 27 2016 04:38
@kirbyedy what editor have you used to do that with? I've tried Fiddle and JS.do and both come up blank.
choose javascript in the dropdown
you might want to add console.log() if you want to see the actual result
but its nice because it will visualise what your loops are doing and so on... step by step
Doug
@Spazcool
Apr 27 2016 04:40
@kirbyedy that'll do pig, that'll do. ;) Thanks a lot.
CamperBot
@camperbot
Apr 27 2016 04:40
spazcool sends brownie points to @kirbyedy :sparkles: :thumbsup: :sparkles:
:star: 925 | @kirbyedy | http://www.freecodecamp.com/kirbyedy
Kelvin-penang
@Kelvin-penang
Apr 27 2016 04:42
Sorry, my bad. totally missed the point.
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 27 2016 04:42
thank you @CatalinScr
CamperBot
@camperbot
Apr 27 2016 04:42
pabbashivaramkaushil sends brownie points to @catalinscr :sparkles: :thumbsup: :sparkles:
:star: 356 | @catalinscr | http://www.freecodecamp.com/catalinscr
V Arun Kumar
@arunvkumr
Apr 27 2016 04:46
Hey, guys.. i'm working on calculator app. it's not complete yet, but works for almost all of the operations. i would like to get some feedback on this. like design, bugs, calculation problems, anythings. here the link. http://codepen.io/arunkumrv/full/JXarKg
D.Mills
@millsdee74
Apr 27 2016 04:52
@aleeex @rodneystrong thanks for FALSE NEGATIVE: Comparison with the Greater Than
CamperBot
@camperbot
Apr 27 2016 04:52
millsdee74 sends brownie points to @aleeex and @rodneystrong :sparkles: :thumbsup: :sparkles:
:warning: could not find receiver for aleeex
:star: 161 | @rodneystrong | http://www.freecodecamp.com/rodneystrong
rkrussel
@rkrussel
Apr 27 2016 05:04

var myObj = {
gift: "pony",
pet: "kitten",
bed: "sleigh"
};

function checkObj(checkProp) {
// Your Code Here
if (myObj.hasOwnProperty(checkProp)){
return checkProp;
}else{
return "Not Found";
}
}

// Test your code by modifying these values
checkObj("pet");

can anyone help me here
Pabba Shiva Ram Kaushil
@PabbaShivaRamKaushil
Apr 27 2016 05:04
@Kelvin-penang acn you help me with make objects prop private
Markus Kiili
@Masd925
Apr 27 2016 05:09
@rkrussel You are returning the property key.
rkrussel
@rkrussel
Apr 27 2016 05:10
how do i return the value
Markus Kiili
@Masd925
Apr 27 2016 05:10
@rkrussel You can access property value with syntax obj[key].
rkrussel
@rkrussel
Apr 27 2016 05:12
doesn't seem to work
Markus Kiili
@Masd925
Apr 27 2016 05:14
@rkrussel Post your code please.
Bhaven Kakade
@thisisbhaven
Apr 27 2016 05:15
Can anyone help me with ‘Record collection’?
I tried this:
// Setup
var collection = {
    2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    2468: {
      album: "1999",
      artist: "Prince",
      tracks: [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    1245: {
      artist: "Robert Palmer",
      tracks: [ ]
    },
    5439: {
      album: "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

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

  if (value !== "" && prop !== "tracks") {
    collection.id[prop] = value;
  }
  if (value !== "" && prop === "tracks") {
    collection.id[prop].push(value);
  }
  if (value === "") {
    collection.id.remove(prop);
  }
  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA”);
It is showing -
TypeError: Attempted to assign to readonly property.
rkrussel
@rkrussel
Apr 27 2016 05:17
im sorry i dont know how to do that
Bhaven Kakade
@thisisbhaven
Apr 27 2016 05:18
Updated
// Setup
var collection = {
    2548: {
      album: "Slippery When Wet",
      artist: "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    2468: {
      album: "1999",
      artist: "Prince",
      tracks: [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    1245: {
      artist: "Robert Palmer",
      tracks: [ ]
    },
    5439: {
      album: "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

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

  if (value !== "" && prop !== "tracks") {
    collection[id][prop] = value;
  }
  if (value !== "" && prop === "tracks") {
    collection[id][prop].push(value);
  }
  if (value === "") {
    collection[id].remove(prop);
  }
  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
This time I’m using bracket notation
TypeError is gone
But still not the correct answer
rkrussel
@rkrussel
Apr 27 2016 05:21
how do i post my code like that ^^
Bhaven Kakade
@thisisbhaven
Apr 27 2016 05:22
Use three backticks before your code
Like this ```
Write your code here.
clear with record collection!
Had to use delete
:smile:
Michael Karpinski
@karpimpski
Apr 27 2016 05:32
@thisisbhaven do you not have to do ```js?
that's what I o
do*
Markus Kiili
@Masd925
Apr 27 2016 05:38
This message was deleted
Tobechukwu
@tobzy
Apr 27 2016 05:41
Hi, everyone. I have some experience with Java. However, JS seems a lot more expressive. I've started a course and there's a lot to learn. Please I need someone to recommend a good book on ES6. After all, it's the language of the future.
Markus Kiili
@Masd925
Apr 27 2016 05:41
@tobechukwu123 I like "Speaking javascript". Free to read online also.
Zach
@Moose1551
Apr 27 2016 05:41
If I were to include an "if statement" in my code, would I nest it inside the "for loop," or would I nest the "for loop" inside the "if statement"?
function truncateString(str, num) {
str = str.slice(0, num - 3);
var stringEnd = "...";


for (var i = 0; i < str; i++) {
  str += str + stringEnd;
}  return str + stringEnd;
  }

truncateString("A-tisket a-tasket A green and yellow basket", 11);
Tobechukwu
@tobzy
Apr 27 2016 05:46
@Masd925 Thanks a bunch.
CamperBot
@camperbot
Apr 27 2016 05:46
tobechukwu123 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1416 | @masd925 | http://www.freecodecamp.com/masd925
V Arun Kumar
@arunvkumr
Apr 27 2016 05:50
@Moose1551 Both can be done. it depends on what you want the code to do.
Bhaven Kakade
@thisisbhaven
Apr 27 2016 05:52
@karpimpski ``` will do :smile:
Tobechukwu
@tobzy
Apr 27 2016 05:55
@camperbot I want some brownie points... Pleaseeeeeeeeeeeeeeeeee
I think the CamperBot is broken. Someone should look at him.
Zach
@Moose1551
Apr 27 2016 06:02
I've passed the first two tests in "Truncate a String," but now I'm having serious issues with the remaining tests. Should I put all of this in a chained if/else statement with each statement containing a for loop? Can I redefine "str" after the first return?
function truncateString(str, num) {
str = str.slice(0, num - 3);
var stringEnd = "...";


for (var i = 0; i < str; i++) {

}  return str + stringEnd;
} 

truncateString("A-tisket a-tasket A green and yellow basket", 11);
Boyce
@Yijianc
Apr 27 2016 06:08
help Pig Latin
CamperBot
@camperbot
Apr 27 2016 06:08

:point_right: algorithm pig latin [wiki]

Problem Explanation:

  • You need to create a program that will translate from English to Pig Latin. Check the instructions for converting to Pig Latin from the initial description or the wiki page. It might not be obvious but you need to remove all the consonants up to the first vowel in the case there letter does not start with a vowel.
:pencil: read more about algorithm pig latin on the FCC Wiki
Spencer Kuzara
@kodaxx
Apr 27 2016 06:22
I feel like the openweathermap free API really doesn't work all the time. It's hard for me to tell if it's my code or the API not responding right. Guess I'll throw in some console logs and see whats going on. Can anyone else test this for me also?
kirbyedy
@kirbyedy
Apr 27 2016 06:25
@kodaxx works here :thumbsup:
Spencer Kuzara
@kodaxx
Apr 27 2016 06:25
Awesome, isn't working here for some reason
Eldar Tinjić
@EldarT90
Apr 27 2016 06:25
need help with several issues with my JS calculator, tnx
Spencer Kuzara
@kodaxx
Apr 27 2016 06:26
My console is returning nothing also. Not getting response from API I guess...
Thank you @kirbyedy
CamperBot
@camperbot
Apr 27 2016 06:26
kodaxx sends brownie points to @kirbyedy :sparkles: :thumbsup: :sparkles:
:star: 927 | @kirbyedy | http://www.freecodecamp.com/kirbyedy
Cory Walker
@cwalker88
Apr 27 2016 06:27
any of y'all lovely folks have time to help explain this javscript module I can't tell exactly why it is confusing to me
Spencer Kuzara
@kodaxx
Apr 27 2016 06:29
@cwalker88 which one?
Cory Walker
@cwalker88
Apr 27 2016 06:30
trying to copy the mark down
Spencer Kuzara
@kodaxx
Apr 27 2016 06:30
Use ```js
Followed by the code and then ```
Cory Walker
@cwalker88
Apr 27 2016 06:31

'''jsfunction nextInLine(arr, item) {
nextInLine(arr, 5)(item, 1)// Your code here

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));'''

CamperBot
@camperbot
Apr 27 2016 06:31
:bulb: to format code use backticks! ``` more info
Cory Walker
@cwalker88
Apr 27 2016 06:31

```jsfunction nextInLine(arr, item) {
nextInLine(arr, 5)(item, 1)// Your code here

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));```

Spencer Kuzara
@kodaxx
Apr 27 2016 06:33
Sorry, the backticks need to be on their own line
Cory Walker
@cwalker88
Apr 27 2016 06:33
function nextInLine(arr, item) {
  nextInLine(arr, 5)(item, 1)// Your code here

  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));
thank you
hahaha sorry about that I'm new to the help chat
I erased my own code because it was messs
Spencer Kuzara
@kodaxx
Apr 27 2016 06:34
What is the goal?
Cory Walker
@cwalker88
Apr 27 2016 06:34
oh actually I didnt
Spencer Kuzara
@kodaxx
Apr 27 2016 06:35
What challenge are you on, I mean
Orsini
@jrorsini
Apr 27 2016 06:35
Hello guys, I’m kind of in trouble here
function chunkArrayInGroups(arr, size) {
  // Break it up.
  var arrGrp = [];
  var arrSubGrp = [];
  for(var i = 0; i <= ((arr.length/size+1)); i+=size) {
    arrSubGrp = arr.slice(i,i+size);
    arrGrp.push(arrSubGrp);
  }
  return arrGrp;
}

chunkArrayInGroups([0, 1, 2, 3, 4, 5], 4);
This is for the Chunky Monkey
Cory Walker
@cwalker88
Apr 27 2016 06:35
its JS way point 194 the point is to 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 nextIn Line function should then return the element that was removed
194 "Stand in Line"
Orsini
@jrorsini
Apr 27 2016 06:36
I just don’t see how to slice the remaining piece of array to add to my big array
If that makes sense
Eldar Tinjić
@EldarT90
Apr 27 2016 06:37
https://codepen.io/EldarT/pen/YqjJBx - why are my buttons with class op not disabled
Orsini
@jrorsini
Apr 27 2016 06:37
Like that [[0, 1, 2, 3], [4, 5]] for chunkArrayInGroups([0, 1, 2, 3, 4, 5], 4)
Spencer Kuzara
@kodaxx
Apr 27 2016 06:38
Find stand in line
CamperBot
@camperbot
Apr 27 2016 06:38

find stand in line

:zero: checkpoint stand in line

Spencer Kuzara
@kodaxx
Apr 27 2016 06:41
@cwalker88 you'll be using .push and .shift
Are you familiar with those methods?
Cory Walker
@cwalker88
Apr 27 2016 06:42
oh okay yes I vaguely remeber the last que way point
Spencer Kuzara
@kodaxx
Apr 27 2016 06:43
So first use push to push the parameter item to the end on the array
Sorry, I'm on my mobile. Hard to type
Cory Walker
@cwalker88
Apr 27 2016 06:44
how do I call the number I bumped with .push
the arr argument?
Spencer Kuzara
@kodaxx
Apr 27 2016 06:45
The arr argument would be the array that you are pushing to, the item is the number
Cory Walker
@cwalker88
Apr 27 2016 06:46
okay thank you!
Spencer Kuzara
@kodaxx
Apr 27 2016 06:46
We can do this one line at a time, no prob
Show me what you got
@cwalker88
Cory Walker
@cwalker88
Apr 27 2016 06:50
function nextInLine(arr, item) {
  nextInLine(arr, 5)(item, 1)// Your code here
  item .push([6]) 
  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));
kirbyedy
@kirbyedy
Apr 27 2016 06:50
@cwalker88 you have to push the number to the array
your array is arr, and number is item
do not hard code it by writing the number 6
Zach
@Moose1551
Apr 27 2016 06:51
Can anyone tell me why I'm returning "SyntaxError: Unexpected token else"? Is this not the way to use chained if/else statements?
function truncateString(str, num) {
var longEnoughStr = str.slice(0, num - 3);
var numThreeAndDown = str.slice(0, num);
var stringEnd = "...";

if (num > 3 && str === str) 
  for (var i = 0; i < longEnoughStr; i++) {
  return longEnoughStr + stringEnd;
} else if (num <= 3)
   for (var j = 0; j < numThreeAndDown; j++) {
   return numThreeAndDown + stringEnd;
} else {
  return str;
}
}
truncateString("A-tisket a-tasket A green and yellow basket", 11);
Cory Walker
@cwalker88
Apr 27 2016 06:52
arr.push(item);
something like that
Spencer Kuzara
@kodaxx
Apr 27 2016 06:52
@cwalker88 there you go!
kirbyedy
@kirbyedy
Apr 27 2016 06:53
@Moose1551 use the: http://www.pythontutor.com/visualize.html#mode=display to visualise your code
Spencer Kuzara
@kodaxx
Apr 27 2016 06:54
Because we want to manipulate the array which we've named arr, we use the .push on that. What are we pushing? The item! So yes, what you have for the first task is correct @cwalker88
Cory Walker
@cwalker88
Apr 27 2016 06:54
@kodaxx getting SyntaxError: illegal return statement
so Im only half done
Spencer Kuzara
@kodaxx
Apr 27 2016 06:54
Yes only half done
You still need use shift to take the first number off, and then the goal is to return that
Cory Walker
@cwalker88
Apr 27 2016 06:55
and I can do that in the same function
Spencer Kuzara
@kodaxx
Apr 27 2016 06:55
So, you'll want to store the shifted number in a variable
Yes, just on the next line down
You can do many many things inside a function. The idea of a function is to take many lines of code that you will use often and store them in a function. So you can use one line to accomplish a larger task
@cwalker88
Cory Walker
@cwalker88
Apr 27 2016 06:58
but the function has to make sense you can't just put anything in there or it won't execute in this case if I create line item.shift(arr);
wont that create a loop
Prateek
@Prat99
Apr 27 2016 06:58
I m stuck in golf problem in javascript
Spencer Kuzara
@kodaxx
Apr 27 2016 06:58
So after you've pushed the item to the array, next line down, create a variable. We'll call it shifted
Prateek
@Prat99
Apr 27 2016 06:58
I m not able to understand the problem
please help
could anybody please elaborate the problem
Cory Walker
@cwalker88
Apr 27 2016 06:59
var shifted = nextInLine
like so?
Spencer Kuzara
@kodaxx
Apr 27 2016 07:00
@cwalker88 just the variable. We want the variable to equal the item that we'll shift off the front of the array
So, just as you did the push, do the shift
Cory Walker
@cwalker88
Apr 27 2016 07:01
ok so I created the variable shifted I assign it to item
Spencer Kuzara
@kodaxx
Apr 27 2016 07:01
So var shifted = arr.shift(item);
See what I'm saying?
Cory Walker
@cwalker88
Apr 27 2016 07:01
oh all of it okay
Prateek
@Prat99
Apr 27 2016 07:02
@kodaxx
Spencer Kuzara
@kodaxx
Apr 27 2016 07:02
Sorry though, I'm wrong. You don't need to put item in there
Cory Walker
@cwalker88
Apr 27 2016 07:02
do I need blank parenths
Spencer Kuzara
@kodaxx
Apr 27 2016 07:02
Because shift will automatically do first number, yes blank
Cory Walker
@cwalker88
Apr 27 2016 07:02
to place hold the number object
Spencer Kuzara
@kodaxx
Apr 27 2016 07:03
So, var shifted = arr.shift();
Zach
@Moose1551
Apr 27 2016 07:03
@kirbyedy , can you add to that a little? haha...
Spencer Kuzara
@kodaxx
Apr 27 2016 07:04
That will take the array you've passed to the function, shift off the first number and store it in variable shifted
Now we want to return that variable
@cwalker88
Cory Walker
@cwalker88
Apr 27 2016 07:04
function nextInLine(arr, item) {
  nextInLine(arr, 5)(item, 1)// Your code here
  arr.push(item); 
  var shifted = 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));
I didnt mean to send that one sorry
Spencer Kuzara
@kodaxx
Apr 27 2016 07:05
I see 2 small problems
Boyce
@Yijianc
Apr 27 2016 07:05
help DNA Pairing
CamperBot
@camperbot
Apr 27 2016 07:05

:point_right: algorithm dna pairing [wiki]

Problem Explanation:

  • You will get a DNA strand sequence and you need to get the pair and return it as a 2D array of the base pairs. Keep in mind that the provided strand should be first always.

:pencil: read more about algorithm dna pairing on the FCC Wiki

kirbyedy
@kirbyedy
Apr 27 2016 07:06
@Moose1551 well your syntax is wrong
Spencer Kuzara
@kodaxx
Apr 27 2016 07:06
@cwalker88 2 small problems. You want your return statement inside the function, and you'll want to return shifted
Cory Walker
@cwalker88
Apr 27 2016 07:06
ok
kirbyedy
@kirbyedy
Apr 27 2016 07:06
brackets missing in those if else statements
Spencer Kuzara
@kodaxx
Apr 27 2016 07:07
@cwalker88 is it working for you?
Cory Walker
@cwalker88
Apr 27 2016 07:07
function nextInLine(arr, item) {
  nextInLine(arr, 5)(item, 1)// Your code here
  arr.push(item);
  var shifted = 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));
UtkarshShukla7
@UtkarshShukla7
Apr 27 2016 07:07
@Prat99 you just have to use simple if-else logic
Cory Walker
@cwalker88
Apr 27 2016 07:08
syntax error lines 2 and 5 illegal return statement
Prateek
@Prat99
Apr 27 2016 07:08
@UtkarshShukla7 could you please elaborate the problem
Spencer Kuzara
@kodaxx
Apr 27 2016 07:08
@cwalker88 you're still returning the item, what good will that do? You posted the item to the function as a parameter, remember?
Cory Walker
@cwalker88
Apr 27 2016 07:09
so I call the function instead
return shifted
?
Spencer Kuzara
@kodaxx
Apr 27 2016 07:09
Yes
UtkarshShukla7
@UtkarshShukla7
Apr 27 2016 07:09
@Prat99 like check if(stroke==1) return "Hole-in-one"
Spencer Kuzara
@kodaxx
Apr 27 2016 07:10
Though, shifted is not your function, it's a variable inside your function containing the number you've shifted off the front of the array @cwalker88
Cory Walker
@cwalker88
Apr 27 2016 07:10
right i still have a Syntax Error reportung
Spencer Kuzara
@kodaxx
Apr 27 2016 07:10
Yes
At the end of the shifted line, there is a problem. Do you see it?
Cory Walker
@cwalker88
Apr 27 2016 07:11
extra bracket
Spencer Kuzara
@kodaxx
Apr 27 2016 07:12
Yes
Cory Walker
@cwalker88
Apr 27 2016 07:12
i fixed that now it says maximum call stack size exceeded
Spencer Kuzara
@kodaxx
Apr 27 2016 07:12
Also, not sure what the first line after the function is for
Prateek
@Prat99
Apr 27 2016 07:12
@UtkarshShukla7 thankx a lot
Spencer Kuzara
@kodaxx
Apr 27 2016 07:12
The second line in the program, did you put that there? @cwalker88
I think erasing that should get you to your goal
Cory Walker
@cwalker88
Apr 27 2016 07:13
yes that was left over from before I sought help yes
there we go I commented it out and it worked thank you
Spencer Kuzara
@kodaxx
Apr 27 2016 07:14
Yes no problem
UtkarshShukla7
@UtkarshShukla7
Apr 27 2016 07:14
@Prat99 np
Cory Walker
@cwalker88
Apr 27 2016 07:20
thanks @kodaxx
CamperBot
@camperbot
Apr 27 2016 07:20
cwalker88 sends brownie points to @kodaxx :sparkles: :thumbsup: :sparkles:
:star: 299 | @kodaxx | http://www.freecodecamp.com/kodaxx
Rawan44
@Rawan44
Apr 27 2016 07:23
Hello I couldn't find an error
function chunkArrayInGroups(arr, size) {
  // Break it up.
  var n;
  var a = [];
  if (arr % size === 0)
    n = arr / size;
  else
    n = arr / size + 1;
  for (i=0; i<n; i++) {
    a.push(arr.slice(i*size, i*size+size));
  }
  return a;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
Boyce
@Yijianc
Apr 27 2016 07:23
help Missing letters
CamperBot
@camperbot
Apr 27 2016 07:23

:point_right: algorithm missing letters [wiki]

Problem Explanation:

  • You will create a program that will find the missing letter from a string and add it. If there is not missing letter it will return undefined. There is currently no test case for it missing more than one letter, but if anything recursion can be implemented or a second or more calls to the same function as needed. Also the letters are always provided in order so there is no need to sort them.
:pencil: read more about algorithm missing letters on the FCC Wiki
Swaraj Kumar Dehuri
@skdehuri
Apr 27 2016 07:25
hello everyone, I am having some problem in a challenge. I need some help.
Nelmie Turla
@nelmie
Apr 27 2016 07:25

var Car = function() {
// this is a private variable
var speed = 10;

// these are public methods
this.accelerate = function(change) {
speed += change;
};

this.decelerate = function() {
speed -= 5;
};

this.getSpeed = function() {
return speed;
};
};

var Bike = function() {

// Only change code below this line.
var gear = 5;

this.setGear = function(){
gear -= 1;
};
this.getGear = function(){
return gear;
};
};

var myCar = new Car();

var myBike = new Bike();
var Car = function() {
// this is a private variable
var speed = 10;

// these are public methods
this.accelerate = function(change) {
speed += change;
};

this.decelerate = function() {
speed -= 5;
};

this.getSpeed = function() {
return speed;
};
};

var Bike = function() {

// Only change code below this line.
var gear = 5;

this.setGear = function(){
gear -= 1;
};
this.getGear = function(){
return gear;
};
};

var myCar = new Car();

var myBike = new Bike();

sorry for pasting double, i just dont know the missing piece here
Jérôme
@ajie62
Apr 27 2016 07:31

Hi everyone! I'd like to know if you could help me. I'm stuck at "Using Objects for Lookups". I've been trying and getting no postive result... So far, I've got this:

// Setup
function phoneticLookup(val) {
  var result = "";

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

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

// Change this value to test
phoneticLookup("charlie");

So I've created the lookup table as asked in the instructions, but then they say: "Use it to lookup val and assign the associated string to the result variable...

UtkarshShukla7
@UtkarshShukla7
Apr 27 2016 07:35
@ajie62 you have return chicago if charlie is passed to function and you are returning the whole object
Apoorve
@apugoneappu
Apr 27 2016 07:38

Challenge: Mutations

function mutation(arr) {
  var arr1 = arr[0].toLowerCase();
  var arr2 = arr[1].toLowerCase();
  //return arr1.indexOf(arr2[2]);
  for (var i = 0; i < arr2.length; i++) {
    if (arr1.indexOf(arr2[i]) == -1) {
      return false;
    }
    else {
    return true;
    }
  }


}

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

This is the only case that's not working.

Swaraj Kumar Dehuri
@skdehuri
Apr 27 2016 07:38
I need some help in 'Stand in Line' challenge
Apoorve
@apugoneappu
Apr 27 2016 07:38
This message was deleted
Swaraj Kumar Dehuri
@skdehuri
Apr 27 2016 07:38
This message was deleted
Jérôme
@ajie62
Apr 27 2016 07:39
@UtkarshShukla7 Ok, so how should I do that?
UtkarshShukla7
@UtkarshShukla7
Apr 27 2016 07:39
@ajie62 access value of properties using [] or . operator
Swaraj Kumar Dehuri
@skdehuri
Apr 27 2016 07:40
function nextInLine(arr, item) {
  // Your code here

  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));
UtkarshShukla7
@UtkarshShukla7
Apr 27 2016 07:40
@ajie62 like return lookup[val];
Markus Kiili
@Masd925
Apr 27 2016 07:40
@apugoneappu Return true after the loop.
Jérôme
@ajie62
Apr 27 2016 07:41

@UtkarshShukla7 But they say

// Only change code above this line
  return result;

So I already made a mistake. i can't change this line...

Apoorve
@apugoneappu
Apr 27 2016 07:41
@Masd925 Why?
UtkarshShukla7
@UtkarshShukla7
Apr 27 2016 07:42
@apugoneappu it is not checking the whole string
return after loop terminates
Yaroslav
@YVeselovskyi
Apr 27 2016 07:42
hello :)
UtkarshShukla7
@UtkarshShukla7
Apr 27 2016 07:42
@ajie62 then result=lookup[val];
Yaroslav
@YVeselovskyi
Apr 27 2016 07:42
//Set topDistance
var topDistance = 0;

for (var m = 0; m < cosineValues.length; m++) {
    topDistance += cosineValues[m];
}

for(var j=0; j< cosinus.length; j++){
  cosinus[j].style.top = topDistance+'px';
}
Markus Kiili
@Masd925
Apr 27 2016 07:42
@apugoneappu So you return true after you have checked that all the characters are in the first string.
Yaroslav
@YVeselovskyi
Apr 27 2016 07:42
how to make cosinus[j].style.top change every iteration?
in the second loop
tushar3112
@tushar3112
Apr 27 2016 07:42
Hey guys, I was wondering if you guys could help me with my tic-tac-toe zipline. i am stuck really bad. I think there's some problem with my "Ai()" function. I have all my functions in a "game()" function at the end of the js file which will be triggered when a user clicks on the game-board. I would really appreciate your help. http://codepen.io/tushar_13/pen/zqPQOp
Jérôme
@ajie62
Apr 27 2016 07:44
@UtkarshShukla7 I did it. Thank you!
CamperBot
@camperbot
Apr 27 2016 07:44
ajie62 sends brownie points to @utkarshshukla7 :sparkles: :thumbsup: :sparkles:
:star: 383 | @utkarshshukla7 | http://www.freecodecamp.com/utkarshshukla7
Apoorve
@apugoneappu
Apr 27 2016 07:44
@Masd925 The resulting changes to be?
UtkarshShukla7
@UtkarshShukla7
Apr 27 2016 07:45
@ajie62 np
Vivek
@vivek28111992
Apr 27 2016 07:47
does anybody know angular here
Apoorve
@apugoneappu
Apr 27 2016 07:47
@Masd925 There?
UtkarshShukla7
@UtkarshShukla7
Apr 27 2016 07:49
@apugoneappu just remove the else return true part from for loop and return true outside loop
Apoorve
@apugoneappu
Apr 27 2016 07:51
@UtkarshShukla7 It worked! But why?
UtkarshShukla7
@UtkarshShukla7
Apr 27 2016 07:52
@apugoneappu because when it was checking in the loop if first character matched in both the arrays it returned true without checking the next element of array
D.Mills
@millsdee74
Apr 27 2016 07:53

Comparisons with the Logical And Operator. I have this........... function testLogicalAnd(val) {
// Only change code below this line

if (val <= 25 && num >= 50) {
return "Yes";
}

// Only change code above this line
return "NO";
}

// Change this value to test
testLogicalAnd(10);
Can anyone help???

Apoorve
@apugoneappu
Apr 27 2016 07:54
@UtkarshShukla7 Thanks a ton!
CamperBot
@camperbot
Apr 27 2016 07:54
apugoneappu sends brownie points to @utkarshshukla7 :sparkles: :thumbsup: :sparkles:
:star: 384 | @utkarshshukla7 | http://www.freecodecamp.com/utkarshshukla7
UtkarshShukla7
@UtkarshShukla7
Apr 27 2016 07:54
@apugoneappu np
D.Mills
@millsdee74
Apr 27 2016 07:56
It says number is not defined
UtkarshShukla7
@UtkarshShukla7
Apr 27 2016 08:00
This message was deleted
@millsdee74 if (val <= 25 && num >= 50) num should be val
Jérôme
@ajie62
Apr 27 2016 08:03
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
  myObj.hasOwnProperty();

  return "Change Me!";
}

// Test your code by modifying these values
checkObj("gift");
It's about Testing Objects for Properties... :'(
D.Mills
@millsdee74
Apr 27 2016 08:04
@UtkarshShukla7 I put 30 there and it still does work
UtkarshShukla7
@UtkarshShukla7
Apr 27 2016 08:05
@millsdee74 what is the error
Yaroslav
@YVeselovskyi
Apr 27 2016 08:06
Could someone help me?
UtkarshShukla7
@UtkarshShukla7
Apr 27 2016 08:06
@ajie62 myObj.hasOwnProperty(checkProp);
D.Mills
@millsdee74
Apr 27 2016 08:08
@UtkarshShukla7 first it said "num undefined." Now it simply says "NO"
UtkarshShukla7
@UtkarshShukla7
Apr 27 2016 08:08
@millsdee74 and what are the conditions you have to test
D.Mills
@millsdee74
Apr 27 2016 08:09
@UtkarshShukla7 Combine the two if statements into one statement which will return "Yes" if val is less than or equal to 50 and greater than or equal to 25. Otherwise, will return "No".
UtkarshShukla7
@UtkarshShukla7
Apr 27 2016 08:09
@millsdee74 if (val >= 25 && val <= 50)
Markus Kiili
@Masd925
Apr 27 2016 08:12
@vivek28111992 I work using angular.
Jérôme
@ajie62
Apr 27 2016 08:14
Hey @UtkarshShukla7, can you take a look at this code for "Testing Objects for Properties" and tell me if it was the proper way to solve it? The code works, but I have the feeling there was an easier way to do it...
// Setup
var myObj = {
  gift: "pony",
  pet: "kitten",
  bed: "sleigh"
};

function checkObj(checkProp) {
  // Your Code Here
  if (myObj.hasOwnProperty(checkProp) === true) {
    if (checkProp === "gift") {
      return "pony";
    }
    else if (checkProp === "pet") {
      return "kitten";
    }
  } 
  else {
    return "Not Found";
  }
}

// Test your code by modifying these values
checkObj("gift");
D.Mills
@millsdee74
Apr 27 2016 08:14

Still Saying No and these options are still on red.

testLogicalAnd(0) should return "No"
te

testLogicalAnd(51) should return "No"
testLogicalAnd(75) should return "No"
testLogicalAnd(80) shouldstLogicalAnd(24) should

UtkarshShukla7
@UtkarshShukla7
Apr 27 2016 08:16
@ajie62 yes just return myObj[checkProp]; instead of if -else
@millsdee74 change return "NO" to return "No"
Jérôme
@ajie62
Apr 27 2016 08:18
@UtkarshShukla7 you mean like this?
function checkObj(checkProp) {
  // Your Code Here
  myObj.hasOwnProperty(checkProp);
  return myObj[checkprop];
}
It's working, but the instructions ask: "checkObj("house") (doesn't exist) should return "Not Found"
UtkarshShukla7
@UtkarshShukla7
Apr 27 2016 08:20
@ajie62
function checkObj(checkProp) {
  // Your Code Here
  if (myObj.hasOwnProperty(checkProp) === true) {
    return myObj[checkProp];}
  else {
    return "Not Found";
  }
}
Jérôme
@ajie62
Apr 27 2016 08:22
Oh yes, you're right... I'm such an idiot!
V1ad1m1r
@V1ad1m1r
Apr 27 2016 08:24
I cant seem to figure out why my background image switch isnt triggering. :/
each time it pops the default instead of the correct option.
Anyone got any ideas?
Bhaven Kakade
@thisisbhaven
Apr 27 2016 08:26
Check for Palindromes: How do I remove non-alphanumeric characters?
V1ad1m1r
@V1ad1m1r
Apr 27 2016 08:26
help palindromes
CamperBot
@camperbot
Apr 27 2016 08:26

:point_right: algorithm check for palindromes [wiki]

Explanation:

Our goal for solving this problem is tidying up the string passed in, and checking whether it is in fact a palindrome.

  • If you are unsure of what a palindrome is, it is a word or phrase that when reversed spells the same thing forwards or backwards. A simple example is mom, when you reverse the letters, it spells the same thing! Another example of a palindrome is race car. When we take out anything that is not a character it becomes racecar which is the same spelled forwards or backwards!

Once we have determined whether it is a palindrome or not we want to return either true or false based on our findings.

:pencil: read more about algorithm check for palindromes on the FCC Wiki

the doer
@ewathedoer
Apr 27 2016 08:27
@V1ad1m1r where is this image implemented in code?
V1ad1m1r
@V1ad1m1r
Apr 27 2016 08:27
@ewathedoer the image is called through the api, im using its identifier (10n or 50n etc..) to identify which background should be displayed.
@ewathedoer the background image is implemented during the switch
the doer
@ewathedoer
Apr 27 2016 08:31
@V1ad1m1r it displays on Safari
on Chrome it doesn’t work because of API source I think
What broweser do you use to check?
V1ad1m1r
@V1ad1m1r
Apr 27 2016 08:32
yea i had to switch out of chrome, an am trying to get it to work in firefox
the background image displays in safari?
the doer
@ewathedoer
Apr 27 2016 08:32
Chrome’s new version do not accept API without https
V1ad1m1r
@V1ad1m1r
Apr 27 2016 08:33
why would i only be getting the default color background in firefox? hmmmm....
the doer
@ewathedoer
Apr 27 2016 08:33
maybe order?
V1ad1m1r
@V1ad1m1r
Apr 27 2016 08:33
Yea. wish i knew a workaround with the new chrome version, but at the moment...
hmm.. it should run just like an if/ else. and the default is currently last in the order :/
the doer
@ewathedoer
Apr 27 2016 08:34
I gotta dark blue and wether icon both on direfox and Safari
V1ad1m1r
@V1ad1m1r
Apr 27 2016 08:34
ok. good. then its not the browser.
the doer
@ewathedoer
Apr 27 2016 08:34
good luck with debugging
V1ad1m1r
@V1ad1m1r
Apr 27 2016 08:34
So it SHOULD have a background image and a weather icon...
thanks @ewathedoer
CamperBot
@camperbot
Apr 27 2016 08:34
v1ad1m1r sends brownie points to @ewathedoer :sparkles: :thumbsup: :sparkles:
:star: 347 | @ewathedoer | http://www.freecodecamp.com/ewathedoer
V1ad1m1r
@V1ad1m1r
Apr 27 2016 08:37
@thisisbhaven did that help
?
alright. thats enough. Im calling it for the night. Maybe i can get this thing to work tomorrow.
naassi
@naassi
Apr 27 2016 08:43
I can't load one of the challenges because the code crashes the page before it loads, anyone know how i would fix this?
Zach
@Moose1551
Apr 27 2016 08:47
Without giving me a solution, can anyone tell me why my final else statement isn't passing tests 3 or 4 in the Bonfire challenge "Truncate a String"?
function truncateString(str, num) {
  var stringEnd = "...";
  if (num > 3) {
    return str.slice(0, num - 3) + stringEnd;
  } else if (num <= 3 && num > 0) {
    return str.substr(0, num) + stringEnd;
  } else {
    return str;
  }

}
truncateString("A-tisket a-tasket A green and yellow basket", 11);
Bhaven Kakade
@thisisbhaven
Apr 27 2016 08:50
@V1ad1m1r I implemented different logic
Shamsul Anuar Abdul Wahid
@sawahid
Apr 27 2016 08:51
I'm doing one of the challenge, I can see that from the display of the test case output my program is giving the right output, but the challenge run test giving status fail even the output is the same.
pompek
@pompek
Apr 27 2016 08:51

@V1ad1m1r change your cases to:

case "01n":

and so on

Bhaven Kakade
@thisisbhaven
Apr 27 2016 08:54
Use replace(/[^a-z|1-9]/g, “”)
Jonathon Lopez
@JonathonLLopez
Apr 27 2016 08:59
How do you show the code from a challenge? I'm having trouble even understanding the objective of this challenge.
Zach
@Moose1551
Apr 27 2016 09:00
Anyone? I keep plugging it in to different tests, and everywhere else except for this particular challenge displays the desired effect.
@JonathonLLopez , do this:
```js
paste your code below the ```js
Codemzy
@codemzy
Apr 27 2016 09:00
wiki format
CamperBot
@camperbot
Apr 27 2016 09:00

: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

:pencil: read more about code formatting on the FCC Wiki

Zach
@Moose1551
Apr 27 2016 09:00
and then close it with:
Codemzy
@codemzy
Apr 27 2016 09:01
@JonathonLLopez :point_up_2:
Zach
@Moose1551
Apr 27 2016 09:01
```
This message was deleted
This message was deleted
Jonathon Lopez
@JonathonLLopez
Apr 27 2016 09:06
function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) {
  var result = "";
  // Your code below this line


  // Your code above this line
  return result;
}

// Change the words here to test your function
wordBlanks("dog", "big", "ran", "quickly");

Thank you for the help! Now, here are the instructions:

You will need to use string operators to build a new string, result, using the provided variables: myNoun, myAdjective, myVerb, and myAdverb.

You will also need to provide additional strings, which will not change, in between the provided words.

We have provided a framework for testing your results with different words. The tests will run your function with several different inputs to make sure all of the provided words appear in the output, as well as your extra strings.

I'm not sure I even understand what I'm supposed to do
Messe
@M3SSI4H
Apr 27 2016 09:08

function palindrome(str) {
var str1 = str.replace(/\W/g, '').toLowerCase().replace(/[0-9]/g, '').reverse();
if (str1 == str.replace(/\W/g, '').toLowerCase().replace(/[0-9]/g, '')) {
return true;
} else {
return false;
}

}
palindrome("race car");

Markus Kiili
@Masd925
Apr 27 2016 09:12
@M3SSI4H You are not supposed to remove numbers.
@M3SSI4H First replace and lowercase. Then do palindromicality check.
pompek
@pompek
Apr 27 2016 09:15
@JonathonLLopez you need to return a sentence using the given parameters in correct order and put spaces in between
Messe
@M3SSI4H
Apr 27 2016 09:31
function palindrome(str) {
str = str.replace(/\W/g, '').toLowerCase().replace(/_/g, "");
var str1 = str.replace(/\W/g, '').toLowerCase().replace(/_/g, "");
if (str1.split('').reverse().join("") == str) {
return true;
} else {
return false;
}
}
palindrome("0_0 (: /-\ :) 0-0");
got it! thanks @Masd925
CamperBot
@camperbot
Apr 27 2016 09:32
m3ssi4h sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1417 | @masd925 | http://www.freecodecamp.com/masd925
Messe
@M3SSI4H
Apr 27 2016 09:32
There's probably a much simpler way, but i got it!
Blauelf
@Blauelf
Apr 27 2016 09:41
@M3SSI4H You can combine both regexes to /\W|_/g or /[\W_]/g (or, as I like it, /[^0-9A-Za-z]/g, which means "anything not alphanumeric"), and you don't need both str and str1 (after the first line str holds a "sanitized" version), just do return str == str.split('').reverse().join(''); without any if-else (or remove first line instead of second and do that with str1 instead of str).
Messe
@M3SSI4H
Apr 27 2016 09:44
cool, that should make it a bit cleaner. thanks @Blauelf for the tip :D
CamperBot
@camperbot
Apr 27 2016 09:44
m3ssi4h sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star: 1723 | @blauelf | http://www.freecodecamp.com/blauelf
Vivek
@vivek28111992
Apr 27 2016 09:44
@Masd925 hi, there is one task I have create, can I share with you?
Prabhat Singh
@forceawakened
Apr 27 2016 09:44

why is my code for checking palindrome not working?

function palindrome(str) {
str = str.replace(/[^a-zA-Z0-9]/g, '');
str.toLowerCase();
var i = 0;
var j = str.length-1;
for(; i < j; ++i, --j){
if(str[i] != str[j]){
return false;
}
}
return true;
}

Markus Kiili
@Masd925
Apr 27 2016 09:45
@vivek28111992 Sure.
@forceawakened Strings are immutable, so str.toLowerCase(); does nothing (the new strings vanishes into bit space).
Prabhat Singh
@forceawakened
Apr 27 2016 09:46
Oh! so what should i do
Markus Kiili
@Masd925
Apr 27 2016 09:46
@forceawakened For example str=str.toLowerCase();
Vivek
@vivek28111992
Apr 27 2016 09:46
@Masd925 can I have your e-mail id? it is pdf file
Prabhat Singh
@forceawakened
Apr 27 2016 09:47
thanks @Masd925
CamperBot
@camperbot
Apr 27 2016 09:47
forceawakened sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1418 | @masd925 | http://www.freecodecamp.com/masd925
Boyce
@Yijianc
Apr 27 2016 09:51
help Convert HTML Entities
CamperBot
@camperbot
Apr 27 2016 09:51

:point_right: algorithm convert html entities [wiki]

Problem Explanation:

  • You have to create a program that will convert HTML entities from string to their corresponding HTML entities. There are only a few so you can use different methods.

:pencil: read more about algorithm convert html entities on the FCC Wiki

Vivek
@vivek28111992
Apr 27 2016 10:01
@Masd925 ?
I just want little help and guidance
Markus Kiili
@Masd925
Apr 27 2016 10:03
@vivek28111992 I sent you private message.
Chiara
@chiara-f
Apr 27 2016 10:20
hello guys! can anyone help me with the smallest common multiple algorithm?
function smallestCommons(arr) {
  //sorting the array so that it's always ascending
  arr.sort();
  //finding all numbers between arr[0] and arr[1]
  var range = [];
  for (var i = arr[0]; i <= arr[1]; i++) {
    range.push(i);
  }
  // scm is smallest common multiple
  var scm = range[range.length - 1];
  //placeHolder to keep loop going until we find smallest common multiple
  var placeHolder = true;
  while (placeHolder) {
    scm += 1;
    for (var j = 0; j < range.length; j++) {
      //if it's not scm, break out of for loop
      if (scm%range[j] !== 0) {
        break;
      } else {
        placeHolder = false;
        //smc found...?
      }
    }
  }
  return scm;
}


smallestCommons([1,5]);
this is what i came up with so far
Stephen James
@sjames1958gm
Apr 27 2016 10:22
@chiara-f Does it pass any of the tests?
Chiara
@chiara-f
Apr 27 2016 10:23
@sjames1958gm no :worried:
everything goes well up until i find the range of numbers, that works well, but the while and the for loops don't
Stephen James
@sjames1958gm
Apr 27 2016 10:24
@chiara-f placeholder can only be set false if all of the range are even into scm. You do the first which in this case is 1 and 1 will work for 6
Chiara
@chiara-f
Apr 27 2016 10:26
@sjames1958gm ok i think i'm following you
@sjames1958gm so the problem is where i put the return?
Boyce
@Yijianc
Apr 27 2016 10:27
help Spinal Tap Case
CamperBot
@camperbot
Apr 27 2016 10:27

:point_right: algorithm spinal tap case [wiki]

Problem Explanation:

  • Convert the given string to an all lowercase sentence joined by dashes.
:pencil: read more about algorithm spinal tap case on the FCC Wiki
Stephen James
@sjames1958gm
Apr 27 2016 10:27
@chiara-f no, it is that you set placeHolder inside your for loop not after. placeHolder can only be set false if you never see scm !== 0 after testing all numbers
@Yijianc Help, you need?
Chiara
@chiara-f
Apr 27 2016 10:31
@sjames1958gm so it should be outside the for loop but inside the while, right (otherwise, it may be an infinite loop)?
Sameer Shamsudeen
@sameershamsudheen
Apr 27 2016 10:32
Hi why this code working in Slasher Flick
function slasher(arr, howMany) {
  // it doesn't always pay to be first
  return arr.slice(arr.splice(0, howMany));
}

slasher([1, 2, 3], 2);
Stephen James
@sjames1958gm
Apr 27 2016 10:34
@chiara-f Correct. You could just use a break when you find the SCM.
Here is an abbreviated view of the logic. You start scm one too large [1,2] would return 4
var found = false;
while (true) {
found = true;
for (...) { if ( % !==0) found = false; break}
if (!found) scm++
}
Boyce
@Yijianc
Apr 27 2016 10:34

@sjames1958gm Yes.

str = str.replace(/([a-z])([A-Z])/g, '$1 $2');

what's the string '$1 $2' stands for?

Markus Kiili
@Masd925
Apr 27 2016 10:34
@sameershamsudheen Argument(s) of slice should be number(s). You have an array as an argument there.
Stephen James
@sjames1958gm
Apr 27 2016 10:35
@Yijianc $1 and $2 are set to the values of the matches for the two groupings, characters in () in your Regexp
@Yijianc $1 will be set to the match for [a-z] and $2 will be set to the match for [A-Z]
Sameer Shamsudeen
@sameershamsudheen
Apr 27 2016 10:36
@Masd925 Thank You
CamperBot
@camperbot
Apr 27 2016 10:36
sameershamsudheen sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star: 1419 | @masd925 | http://www.freecodecamp.com/masd925
Mooli
@Mooli88
Apr 27 2016 10:45
hi, can someone give me a hint on how to solve Symmetric Difference ?
should i use recursive function + reduce ? or for loop and reduce? maybe reduce inside reduce ?
Stephen James
@sjames1958gm
Apr 27 2016 10:48
@Mooli88 I used for loop and filter.
Mooli
@Mooli88
Apr 27 2016 10:49
@sjames1958gm thanks i'll try that
CamperBot
@camperbot
Apr 27 2016 10:49
mooli88 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 821 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Chiara
@chiara-f
Apr 27 2016 10:52
@sjames1958gm thanks
CamperBot
@camperbot
Apr 27 2016 10:52
chiara-f sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 822 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Eldar Tinjić
@EldarT90
Apr 27 2016 10:52
@sjames1958gm why is this not working document.getElementsByClassName("op").disabled = false; https://codepen.io/EldarT/pen/YqjJBx
in combo with this
$(".op").click(function() {
 document.getElementsByClassName("op").disabled = true;
});
Stephen James
@sjames1958gm
Apr 27 2016 10:53
@EldarT90 I believe that getElementsByClassName returns an array of matches - put [0] before .disabled if you only have one of class "op"
Eldar Tinjić
@EldarT90
Apr 27 2016 10:56
@sjames1958gm it will disable only 1 element then;
@sjames1958gm let me first tell you what i want; i want if i click for example 3 ++++ 3
that it still returns 6
not got knows how much
so that it register only 1 plus
or *
Stephen James
@sjames1958gm
Apr 27 2016 10:58
document.getElementsByClassName("op")[0].disabled = true; this will disable I tried it
Eldar Tinjić
@EldarT90
Apr 27 2016 10:58
@sjames1958gm yes but it will disable only plus
@sjames1958gm try again with minus or *
Stephen James
@sjames1958gm
Apr 27 2016 10:59
@EldarT90 Then this
var arr = document.getElementsByClassName("op");
arr.forEach(function(e) { e.disabled = true; }
Eldar Tinjić
@EldarT90
Apr 27 2016 11:01
@sjames1958gm wont work :/
Stephen James
@sjames1958gm
Apr 27 2016 11:02
@EldarT90 Why won't it work>
Eldar Tinjić
@EldarT90
Apr 27 2016 11:02
@sjames1958gm maybe i have an error in syntax or something
EricOber
@EricOber
Apr 27 2016 11:02
hey can someone help me with "Selecting from many options with Switch Statements"
Eldar Tinjić
@EldarT90
Apr 27 2016 11:03
EricOber
@EricOber
Apr 27 2016 11:03
^cool
can someone help me?
Eldar Tinjić
@EldarT90
Apr 27 2016 11:07
@Am3ricanPaladin what exactly you have difficulty with
EricOber
@EricOber
Apr 27 2016 11:08
having trouble understanding how to write switch statement code
Stephen James
@sjames1958gm
Apr 27 2016 11:08
@EldarT90 You have a syntax error - red triangle you need another ) before the ;
EricOber
@EricOber
Apr 27 2016 11:08

function caseInSwitch(val) {
var answer = "";
// Only change code below this line
switch (1) {
case 1:
"alpha";
break;
switch (2)
}

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

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

Eldar Tinjić
@EldarT90
Apr 27 2016 11:09
@sjames1958gm but now its broken, it wont even work properly (equal sign)
Chiara
@chiara-f
Apr 27 2016 11:09
This message was deleted
EricOber
@EricOber
Apr 27 2016 11:09
how do i do that
Eldar Tinjić
@EldarT90
Apr 27 2016 11:09
help format
CamperBot
@camperbot
Apr 27 2016 11:09

: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

:pencil: read more about code formatting on the FCC Wiki

Eldar Tinjić
@EldarT90
Apr 27 2016 11:09
post it in proper format first @Am3ricanPaladin
EricOber
@EricOber
Apr 27 2016 11:12

```js
function caseInSwitch(val) {
var answer = "";
// Only change code below this line
switch (1) {
case 1:
"alpha";
break;
switch (2)
cas
}

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

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

Stephen James
@sjames1958gm
Apr 27 2016 11:13
@Am3ricanPaladin Missed the ``` at the end -
@Am3ricanPaladin set answer in your switch or you are only returning ""
EricOber
@EricOber
Apr 27 2016 11:14
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch (1) {
    case 1: 
     "alpha";
      break;
  switch (2)
    cas
  }


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

// Change this value to test
caseInSwitch(1);
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch (1) {
    case 1: 
     "alpha";
      break;
  switch (2)
    cas
  }


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

// Change this value to test
caseInSwitch(1);
sorry im such a newb
Stephen James
@sjames1958gm
Apr 27 2016 11:14
@EldarT90 Should = be disabled along with others - need a more specific identifier. if "op" includes '=' then this disable shouldn't include '=' also - need to enable them all when appropriate.
Eldar Tinjić
@EldarT90
Apr 27 2016 11:14
@sjames1958gm = doesnt contain class op
Stephen James
@sjames1958gm
Apr 27 2016 11:14
@EldarT90 hmm
EricOber
@EricOber
Apr 27 2016 11:15
set answer in my switch?
Stephen James
@sjames1958gm
Apr 27 2016 11:15
@EldarT90 sorry but I have to drive to work - I'll check back in a bit
Samson Alajede
@ajesamson
Apr 27 2016 11:15
@Am3ricanPaladin you switch should contain val
instead of 1
Eldar Tinjić
@EldarT90
Apr 27 2016 11:15
@Am3ricanPaladin you dont need switch every time
@sjames1958gm sure mate np
Stephen James
@sjames1958gm
Apr 27 2016 11:15
@ajesamson switch (---) the value for the switch is in the ---
Eldar Tinjić
@EldarT90
Apr 27 2016 11:15
@sjames1958gm tnx nevertheless
CamperBot
@camperbot
Apr 27 2016 11:15
eldart90 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 823 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
EricOber
@EricOber
Apr 27 2016 11:15
okay?
Eldar Tinjić
@EldarT90
Apr 27 2016 11:16
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch (1) {
    case 1: 
     "alpha";
      break;
    case 2:
"beta";
break;
  }


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

// Change this value to test
caseInSwitch(1);
try in that format
im not sure what the tast is hwoever
Samson Alajede
@ajesamson
Apr 27 2016 11:17
switch(val) {
   case 1:
           break;
   case 2:
           break;
}
EricOber
@EricOber
Apr 27 2016 11:17
what are switches mostly used for anyways
Joshua Swift
@joshuaswift
Apr 27 2016 11:17
function largestOfFour(arr) {
  var numArray = [];

  for (i = 0; i < arr.length; i += 1) {
   numArray = Math.max.apply(Math, arr[i]);
  }
  return numArray;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Eldar Tinjić
@EldarT90
Apr 27 2016 11:17
@Am3ricanPaladin i just posted calculator problem in which i am using it

  switch (whichButton) {
    case "1":
      calc.append("1");
      count = 0;
      break;
    case "2":
      calc.append("2");
      count = 0;
      break;
    case "3":
      calc.append("3");
      count = 0;
      break;
    case "4":
      calc.append("4");
      count = 0;
      break;
    case "5":
      calc.append("5");
      count = 0;
      break;
    case "6":
      calc.append("6");
      count = 0;
      break;
    case "7":
      calc.append("7");
      count = 0;
      break;
    case "8":
      calc.append("8");
      count = 0;
      break;
    case "9":
      calc.append("9");
      count = 0;
      break;
    case "0":
      if (count == 1) {
      calc.append("0");}
      count = 0;
      break;
take a look at that
EricOber
@EricOber
Apr 27 2016 11:17
oh wow
Samson Alajede
@ajesamson
Apr 27 2016 11:17
@Am3ricanPaladin switches are used interchangeably with if
EricOber
@EricOber
Apr 27 2016 11:18
thanks @EldarT90
CamperBot
@camperbot
Apr 27 2016 11:18
:star: 325 | @eldart90 | http://www.freecodecamp.com/eldart90
am3ricanpaladin sends brownie points to @eldart90 :sparkles: :thumbsup: :sparkles:
Samson Alajede
@ajesamson
Apr 27 2016 11:18
but in senarios when you have more condition
you can use if statement when there are few condition to check
Joshua Swift
@joshuaswift
Apr 27 2016 11:18
Hey guys, I'm trying to access the largest number in each sub-array. I can find the largest number in the array as a whole, but I can't figure out how to push the largest number from each sub-array to a new array
Eldar Tinjić
@EldarT90
Apr 27 2016 11:19
@Joshuaswift post your problem
EricOber
@EricOber
Apr 27 2016 11:19
@EldarT90 what is the command "beta" used for?
Joshua Swift
@joshuaswift
Apr 27 2016 11:19
@EldarT90 Hey, I posted it above
@EldarT90 Just before your post
Eldar Tinjić
@EldarT90
Apr 27 2016 11:20
@Joshuaswift i mean post you rcode ^^ to see what it looks like currently
@Am3ricanPaladin i just wrote it as an example, its not a command
@Am3ricanPaladin instead of beta you could write function or command that does something like : return "blabla";
Joshua Swift
@joshuaswift
Apr 27 2016 11:21
@EldarT90 I did! Just before you posted that big code snippet, but don't worry I will post again :)
function largestOfFour(arr) {
  var numArray = [];

  for (i = 0; i < arr.length; i += 1) {
   numArray = Math.max.apply(Math, arr[i]);
  }
  return numArray;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Eldar Tinjić
@EldarT90
Apr 27 2016 11:21
@Joshuaswift sorry
Joshua Swift
@joshuaswift
Apr 27 2016 11:21
The code above currently returns 1001, which is the largest number in the whole array
Eldar Tinjić
@EldarT90
Apr 27 2016 11:21
@Joshuaswift now i see
EricOber
@EricOber
Apr 27 2016 11:21
thanks @ajesamson
CamperBot
@camperbot
Apr 27 2016 11:21
am3ricanpaladin sends brownie points to @ajesamson :sparkles: :thumbsup: :sparkles:
:star: 320 | @ajesamson | http://www.freecodecamp.com/ajesamson
Joshua Swift
@joshuaswift
Apr 27 2016 11:21
@EldarT90 No problem :D
@EldarT90 I just can't figure out how to access each sub-array in turn
Eldar Tinjić
@EldarT90
Apr 27 2016 11:23
@Joshuaswift you need to use arguments i think
@Joshuaswift whats the name of the problem?
Joshua Swift
@joshuaswift
Apr 27 2016 11:23
@EldarT90 Return largest numbers in arrays
Eldar Tinjić
@EldarT90
Apr 27 2016 11:24
@Joshuaswift i used double for loop to check for every element of an array
its not the most efficient way
but it gets the job done
Samson Alajede
@ajesamson
Apr 27 2016 11:24
@Joshuaswift iterate through the array
sort each iteration and return the item in the last index
that will give you largest per iteration
Joshua Swift
@joshuaswift
Apr 27 2016 11:25
@EldarT90 I did wonder whether a nested for loop would work
Samson Alajede
@ajesamson
Apr 27 2016 11:25
@Joshuaswift no need for nested loop
Joshua Swift
@joshuaswift
Apr 27 2016 11:25
@ajesamson Ah that's a good idea, thanks I will try this
CamperBot
@camperbot
Apr 27 2016 11:25
joshuaswift sends brownie points to @ajesamson :sparkles: :thumbsup: :sparkles:
:star: 321 | @ajesamson | http://www.freecodecamp.com/ajesamson
Eldar Tinjić
@EldarT90
Apr 27 2016 11:25
@Joshuaswift it will work and you can do what ajesamson said, or like i did -> whenever checked item is larger than some new variable; that item becoems variable
@ajesamson and in the end just return that variable
Joshua Swift
@joshuaswift
Apr 27 2016 11:26
@EldarT90 thanks also, very helpful
CamperBot
@camperbot
Apr 27 2016 11:26
joshuaswift sends brownie points to @eldart90 :sparkles: :thumbsup: :sparkles:
:star: 326 | @eldart90 | http://www.freecodecamp.com/eldart90
Samson Alajede
@ajesamson
Apr 27 2016 11:26
@EldarT90 yes
he can just push to another array
because i think the question
requires that he extracts the largest of each
Joshua Swift
@joshuaswift
Apr 27 2016 11:27
@ajesamson Yep must return an array of the largest numbers
Eldar Tinjić
@EldarT90
Apr 27 2016 11:27
@ajesamson aha yes; than yeah, push the solution in new array
Samson Alajede
@ajesamson
Apr 27 2016 11:27
and return an array of numbers which are largest
Eldar Tinjić
@EldarT90
Apr 27 2016 11:27
@ajesamson and than return array
so yeah that will work
either way , alwasy try to add little bit of your imagination
Ankit Panwar
@coderNoob
Apr 27 2016 11:27
This is my finished Simon. What do you guys think?
http://codepen.io/coderNoob/full/wGmbqZ/
Eldar Tinjić
@EldarT90
Apr 27 2016 11:27
my codes are certainly not most efficient
but thats good way to learn stuff
when you add some of your idfeas
@coderNoob it looks nice, but maybe the flash is too invasive for eyes
Joshua Swift
@joshuaswift
Apr 27 2016 11:29
@EldarT90 @ajesamson yeah I've been trying hard to think of solutions myself and usually they end up being pretty inefficient. But like you said that's how you learn!
dikeshkumr135
@dikeshkumr135
Apr 27 2016 11:33
Hello Guys I'm stuck at https://www.freecodecamp.com/challenges/word-blanks can;t find a solution
please help
Kevin Galang
@kgalang
Apr 27 2016 11:37
function rot13(str) { // LBH QVQ VG!
 var arr = [];
  var words = str.split(" ");
  for (var i = 0; i < words.length; i++) {
    for (var j = 0; j < words[i].length; j++) {
      arr.push(words[i].charCodeAt(j)-13);
    }
 }
 var toStr = arr.toString();
  return String.fromCharCode(toStr);
}


// Change the inputs below to test
rot13("SERR PBQR PNZC");
Why am I getting a red dot returned? Shouldn't I be getting the letter values from the unicode?
Droiet Operating System
@ayushmaan
Apr 27 2016 11:40
"hello world!"
CamperBot
@camperbot
Apr 27 2016 11:40

welcome to FreeCodeCamp @ayushmaan!

Diego Mayer
@Chrono79
Apr 27 2016 11:45
@kgalang review how String.froCharCode works
its param it's a single charCode, not a string
EricOber
@EricOber
Apr 27 2016 11:46
still having trouble on my switch code
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch () {
    case 1: 
     "alpha";
      break;
    case 2:
      "beta";
      break;
    case 3:
      "gamma;";
      break;
    case 4:
      "delta";
      break;
  }


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

// Change this value to test
caseInSwitch(1);
does anyone know how to fix that?
Diego Mayer
@Chrono79
Apr 27 2016 11:47
@Am3ricanPaladin yes, you have to assign your values to result in each case
and you switch has to evaluate val
EricOber
@EricOber
Apr 27 2016 11:47
ummm how
Diego Mayer
@Chrono79
Apr 27 2016 11:47
how do you set a var value? with =
EricOber
@EricOber
Apr 27 2016 11:47
switch (val) ????
Diego Mayer
@Chrono79
Apr 27 2016 11:47
yes
EricOber
@EricOber
Apr 27 2016 11:48
so i do case = 1:
Diego Mayer
@Chrono79
Apr 27 2016 11:48
no
instead of "alpha"...
use result = "alpha"; and so on
EricOber
@EricOber
Apr 27 2016 11:50
ok lemme try this
not working
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch (val) {
    case 1: 
      result = "alpha";
      break;
    case 2:
      result = "beta";
      break;
    case 3:
      result = "gamma;";
      break;
    case 4:
      result = "delta";
      break;
  }


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

// Change this value to test
caseInSwitch(1);
Diego Mayer
@Chrono79
Apr 27 2016 11:51
@Am3ricanPaladin sorry, instead or result it's answer
EricOber
@EricOber
Apr 27 2016 11:51
oh!
Diego Mayer
@Chrono79
Apr 27 2016 11:51
gotta go, good luck
EricOber
@EricOber
Apr 27 2016 11:51
ooooh ok lets see. thanks @Chrono79
CamperBot
@camperbot
Apr 27 2016 11:51
am3ricanpaladin sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star: 520 | @chrono79 | http://www.freecodecamp.com/chrono79
Sekhar Kolli
@SekharKolli
Apr 27 2016 11:53
@Am3ricanPaladin are you doing good?
@ayushmaan , welcome to FCC
Paul Knight
@pauljohnknight
Apr 27 2016 11:57
Hi
Does anyone know how to get around the bug in exercise 188. On Github it is saying you only have to refresh to over come the bug. This isn't working however. I'm finding these exercises so much better than other sites so am a bit gutted I may not be able to continue. The exercise is around local and global scope in javascript.
anddash
@anddash
Apr 27 2016 11:58
@Chrono79 thanks. helped me too on the switch.
CamperBot
@camperbot
Apr 27 2016 11:58
anddash sends brownie points to @chrono79 :sparkles: :thumbsup: :sparkles:
:star: 521 | @chrono79 | http://www.freecodecamp.com/chrono79
Troels
@Troelsk
Apr 27 2016 11:58
I have the same problem, Paul. I just skipped the challenge, since I get the point.
Sekhar Kolli
@SekharKolli
Apr 27 2016 11:58
@kgalang , were you able to figure out why your loops are not working as expected?
Troels
@Troelsk
Apr 27 2016 11:59
And that was for @pauljohnknight :)
Paul Knight
@pauljohnknight
Apr 27 2016 11:59
Hi Troels - how do i skip a challenge. I can't see a skip button or anything?
Sekhar Kolli
@SekharKolli
Apr 27 2016 12:00
@pauljohnknight , @Troelsk , which exercise is this again please?
Paul Knight
@pauljohnknight
Apr 27 2016 12:00
@SekharKolli number 188
Sekhar Kolli
@SekharKolli
Apr 27 2016 12:01
may I get the title, the number on the top is your brownie points. Brownie points != exercise number :)
Paul Knight
@pauljohnknight
Apr 27 2016 12:01
@Troelsk thanks ignore my last message about how to skip a challenge, i've just worked this out. Thanks
CamperBot
@camperbot
Apr 27 2016 12:01
pauljohnknight sends brownie points to @troelsk :sparkles: :thumbsup: :sparkles:
:star: 165 | @troelsk | http://www.freecodecamp.com/troelsk
Troels
@Troelsk
Apr 27 2016 12:02
The title is "Local Scope and Functions" :)
Not sure what the brownie points are for, except to make me hungry?
Sekhar Kolli
@SekharKolli
Apr 27 2016 12:02
link local scope and functions
EricOber
@EricOber
Apr 27 2016 12:04
can anyone help me with me code?
function switchOfStuff(val) {
  var answer = "";
  // Only change code below this line
  switch (val) {
    case a:
        answer = "apple";
      break;
    case b:
        answer = "bird";
      break;
    case c:
        answer = "cat";
      break;
     default:
          default;



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

// Change this value to test
switchOfStuff(1);
Ken Bellows
@kenbellows
Apr 27 2016 12:05
@Am3ricanPaladin what does 'default: default;` mean to you?
Darth Skywalker
@adityaparab
Apr 27 2016 12:05
@Am3ricanPaladin remove default; That's a syntax error.
Paul Knight
@pauljohnknight
Apr 27 2016 12:06
EricOber
@EricOber
Apr 27 2016 12:06
it is the "Adding a default option in Switch statements
" challenge
Sekhar Kolli
@SekharKolli
Apr 27 2016 12:06
@Am3ricanPaladin , that is correct. your ‘default;’ is invalid
EricOber
@EricOber
Apr 27 2016 12:06
when i try and run it it says "ReferenceError: a is not defined
Ken Bellows
@kenbellows
Apr 27 2016 12:07
@Am3ricanPaladin The point of the defaultstatement is to say "If val doesn't match any of the other cases, use this one instead." So you'll need to either put some valid code in there, or get of it. The default; doesn't mean anything to the browser
Darth Skywalker
@adityaparab
Apr 27 2016 12:07
@Am3ricanPaladin Also I see you have things like case a, case b and case c. That is also syntax error. If you're passing 1 as a parameter, then your cases should be case 1, case 2, case 3
Sekhar Kolli
@SekharKolli
Apr 27 2016 12:07
@pauljohnknight , yeah there is a bug. I solved this exercise by actually declaring a value :)
Ken Bellows
@kenbellows
Apr 27 2016 12:07
@Am3ricanPaladin Oh, also you probably meant to make a, b, and c strings, so you should wrap them in quotes, e.g. case "a":
Samuel Cupidon
@Zerazera
Apr 27 2016 12:08
Hi all, looking for feedback on my Pomodoro clock. http://codepen.io/Zeratul/full/aNKYZL/
Darth Skywalker
@adityaparab
Apr 27 2016 12:08
@kenbellows : case "a" wont work for the parameters that are passed are Numbers.
96street
@96street
Apr 27 2016 12:08

How do arguments work inside a string? for example:

var $orders = $('#orders');
  var $name = $('#name');
  var $drink = $('#drink');

  var orderTemplate = '<li>name: {{name}}, drink: {{drink}}</li>'

  function addOrder(order) {
      $orders.append('<li>name: '+ order.name +', drink: '+order.drink + '</li>');
  }

I thought everything inside a string is treated as just letters and are meaningless. but here the content inside the orderTemplate variable are meaningful

Sekhar Kolli
@SekharKolli
Apr 27 2016 12:09
@pauljohnknight , so I put this line of code var myVar = 0;in the code and commented out the console.log(myVar); line as the comment indicated
Varret
@Varret
Apr 27 2016 12:09
Hi! Is there a way to make JS treat breaklines(enters)in string as a character? I've written JS algorithm that determines how many times a word was used in a string but I want to apply it to long texts and I need to delete every breakline manually
EricOber
@EricOber
Apr 27 2016 12:10
@kenbellows ok that works the quotes that is
Ken Bellows
@kenbellows
Apr 27 2016 12:10
@96street You're right that everything inside a string is in principle meaningless; it's how that string is used later that can make some of its content meaningful. I don't see orderTemplate being used anywhere; is it used later?
EricOber
@EricOber
Apr 27 2016 12:10
@kenbellows thanks
CamperBot
@camperbot
Apr 27 2016 12:10
am3ricanpaladin sends brownie points to @kenbellows :sparkles: :thumbsup: :sparkles:
:star: 43 | @kenbellows | http://www.freecodecamp.com/kenbellows
Ken Bellows
@kenbellows
Apr 27 2016 12:10
@Am3ricanPaladin np ;)
96street
@96street
Apr 27 2016 12:11
@kenbellows
Ken Bellows
@kenbellows
Apr 27 2016 12:11
@Varret If I understand what you're asking, the way to reference newline characters in most languages, including JavaScript, is to use \n
96street
@96street
Apr 27 2016 12:11
Here's the whole function:
$(function() {

  var $orders = $('#orders');
  var $name = $('#name');
  var $drink = $('#drink');

  var orderTemplate = '<li>name: {{name}}, drink: {{drink}}</li>'

  function addOrder(order) {
      $orders.append('<li>name: '+ order.name +', drink: '+order.drink + '</li>');
  }

  $.ajax({
    type:'GET',
    url: 'http://rest.learncode.academy/api/learncode/friends',
    success: function(orders) {
      $.each(orders, function(i, order) {
            addOrder(order);
        }); 
    },
    error: function() {
      alert('Orders not loading');
    }
  });

  $('#addOrder').on('click', function() {

      var order = {
        name: $name.val(),
        drink: $drink.val(),
      };

      $.ajax({
          type: 'POST',
          url: 'http://rest.learncode.academy/api/learncode/friends',
          data: order,
          success: function(newOrder) {
              addOrder(newOrder);
          },
           error: function() {
          alert('Your order could not be posted');
        }
      });

  });




});
@kenbellows
Ken Bellows
@kenbellows
Apr 27 2016 12:13
@96street Hm, it loooks like orderTemplate isn't ever used. Instead, the addOrder function is used to build up a string that happens to be in the same format as orderTemplate, but it never actually references orderTemplate to do so
96street
@96street
Apr 27 2016 12:14
Yeah it's not finished, it shows it here though https://www.youtube.com/watch?v=GbNWPn8vodo&list=PLoYCgNOIyGABdI2V8I_SWo22tFpgh2s6_&index=9 @kenbellows
At 3:52 shows orderTemplate
Boyce
@Yijianc
Apr 27 2016 12:15
@sjames1958gm tks
CamperBot
@camperbot
Apr 27 2016 12:15
yijianc sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 824 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Ken Bellows
@kenbellows
Apr 27 2016 12:16
@96street Right, so what will eventually happen is you will stop using the addOrder() function as it currently is and make use of the Mustache library's Mustache.render() function to parse that string, find all the places where you put {{someVariable}}, and replace it with a value that you've named someVariable
Bhaven Kakade
@thisisbhaven
Apr 27 2016 12:17
Stuck @ Return Largest Numbers in Arrays
Can anyone tell me: How do we compare arrays
?
Ken Bellows
@kenbellows
Apr 27 2016 12:17
@96street Keep watching the video to see that in detail, but to return to your original question, raw strings really don't have any meaning to them, but you can of course give them meaning yourself
Samuel Cupidon
@Zerazera
Apr 27 2016 12:18
@thisisbhaven Javascript doesn't have a native function to compare arrays. You will have to write a procedure yourself.
96street
@96street
Apr 27 2016 12:19
Ahh right that makes sense
thanks @kenbellows
CamperBot
@camperbot
Apr 27 2016 12:19
:star: 44 | @kenbellows | http://www.freecodecamp.com/kenbellows
96street sends brownie points to @kenbellows :sparkles: :thumbsup: :sparkles:
Ken Bellows
@kenbellows
Apr 27 2016 12:19
@96street To get you thinking on the right path, try something like this in your browser console (hit F12) and see what you get:
function sayHi(name) {
  var myTemplate = "Hello {{name}}, how are you doing?";
  console.log(myTemplate.replace('{{name}}', name);
}
sayHi('96street');
sayHi('kenbellows');
Sekhar Kolli
@SekharKolli
Apr 27 2016 12:20
@thisisbhaven , as @Zerazera said, we’ll need to write our own procedure to compare arrays. Use a for loop to traverse array and a if to find / compare with other values
96street
@96street
Apr 27 2016 12:23
I entered it in my console, I can't see anything happening? @kenbellows
Except VM1140:3 Uncaught SyntaxError: missing ) after argument list(…)
Holic
@Holic101
Apr 27 2016 12:23
Hey everybody, I'm stuck at the algorithm "Convert HTML Entities". I can't figure out how to replace multiple different special characters. Here is my code
function convertHTML(str) {
  // &colon;&rpar;

  if (str.indexOf("&") > -1) {
   str = str.replace(/[&]/gi, "&amp;");
  }
  else if (str.indexOf("<") > -1){
    str = str.replace(/[<]/gi, "&lt;");
  }
  else if (str.indexOf(">") > -1){
    str = str.replace(/[>]/gi, "&gt;");
  }
  else if (str.indexOf('"') > -1){
    str = str.replace(/["]/gi, "&quot;");
  }
  else if (str.indexOf("'") > -1){
    str = str.replace(/[']/gi, "&apos;");
  }
  return str;
}

convertHTML("<>");
`
it works with multiple occurences of ONE special characters but not more of them in one string
Stephen James
@sjames1958gm
Apr 27 2016 12:24
@Holic101 You won't want an else if it will only replace the first it finds. Just make them ifs
Bhaven Kakade
@thisisbhaven
Apr 27 2016 12:25
Thank you @Zerazera @SekharKolli
Actually I read the question wrong
I thought we have to return a sub-array which consist largest number of array
But what it really says is return an array with collection of largest numbers of each of sub-array!😅
But thank you.
CamperBot
@camperbot
Apr 27 2016 12:25
thisisbhaven sends brownie points to @zerazera and @sekharkolli :sparkles: :thumbsup: :sparkles:
:star: 293 | @sekharkolli | http://www.freecodecamp.com/sekharkolli
:star: 400 | @zerazera | http://www.freecodecamp.com/zerazera
EricOber
@EricOber
Apr 27 2016 12:25
can anyone help me with my code?
Holic
@Holic101
Apr 27 2016 12:25
@sjames1958gm thank you, beginner mistake :)
CamperBot
@camperbot
Apr 27 2016 12:25
holic101 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 825 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
EricOber
@EricOber
Apr 27 2016 12:25
function sequentialSizes(val) {
  var answer = "";
  // Only change code below this line
  switch (val) {
    case 1: "Low";
    case 2: "Low";
    case 3: "Low";
      answer = "1, 2, or 3"
      break;
    case 4: "Mid";
    case 5: "Mid";
    case 6: "Mid";
      answer = 
      break;
    case 7: "High";
    case 8: "High";
    case 9: "High";
      break;
  }


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

// Change this value to test
sequentialSizes(1);
having trouble here
Stephen James
@sjames1958gm
Apr 27 2016 12:26
@Am3ricanPaladin you need to set answer to the expected return value. Not "1, 2, or 3"
EricOber
@EricOber
Apr 27 2016 12:26
ah ok
Stephen James
@sjames1958gm
Apr 27 2016 12:27
@Am3ricanPaladin The tests should say sequentialSizes(x) returns "something" make your code return what the tests are expecting.
Sekhar Kolli
@SekharKolli
Apr 27 2016 12:27
@Am3ricanPaladin , and the other ‘answer’ line after case 6, needs some value. as a placeholder, you could use answer = “”;
Diego Mayer
@Chrono79
Apr 27 2016 12:28
@Am3ricanPaladin don't forget your ; at the end
EricOber
@EricOber
Apr 27 2016 12:28
ah ty lets see now
Hanan Mufti
@h-ARTS
Apr 27 2016 12:28
how can I access with array.splice() the parameters in a function?
like this: function someThing(argu1, argue2) {
Sekhar Kolli
@SekharKolli
Apr 27 2016 12:29
@Am3ricanPaladin , correct! as @Chrono79 says answer = “1,2 or 3”; \\ should have a semi-colon at the end
Hanan Mufti
@h-ARTS
Apr 27 2016 12:29
argu1.splice(argue2, 0) }
Sekhar Kolli
@SekharKolli
Apr 27 2016 12:30
@h-ARTS , yup you should be able to do that. Are you getting an error?
Stephen James
@sjames1958gm
Apr 27 2016 12:31
@h-ARTS var args = Array.prototype.slice.call(arguments);
Hanan Mufti
@h-ARTS
Apr 27 2016 12:31

```
function slasher(arr, howMany) {
// it doesn't always pay to be first
arr.splice(howMany,0);
return arr;
}

slasher([1, 2, 3], 2);

``` returned [1,2,3]

Stephen James
@sjames1958gm
Apr 27 2016 12:32
@h-ARTS Does splice return a value or modify arr?
Hanan Mufti
@h-ARTS
Apr 27 2016 12:32
it should modify the array
Stephen James
@sjames1958gm
Apr 27 2016 12:33
@h-ARTS Swap your parameters 0, howMany
Hanan Mufti
@h-ARTS
Apr 27 2016 12:35
@sjames1958gm thx :smile:
CamperBot
@camperbot
Apr 27 2016 12:35
h-arts sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star: 826 | @sjames1958gm | http://www.freecodecamp.com/sjames1958gm
Ken Bellows
@kenbellows
Apr 27 2016 12:38
@96street Ah sorry, missed a paren on the console.log(), try this:
function sayHi(name) {
  var myTemplate = "Hello {{name}}, how are you doing?";
  console.log(myTemplate.replace('{{name}}', name));
}
sayHi('96street');
sayHi('kenbellows');
Blauelf
@Blauelf
Apr 27 2016 12:40

@h-ARTS Please note that this way, the result could hold some surprises:

var myArr = [4, 8, 15, 16, 23, 42];
var withoutFirst = slasher(myArr, 1);
console.log(myArr);        // both statements will output [8, 15, 16, 23, 42],
console.log(withoutFirst); // as arr inside slasher is pointing to the same array as myArr, and so changing both

I prefer the side-effect free version

function slasher(arr, howMany) {
  return arr.slice(howMany); // return a new array formed from elements starting at index howMany
}
Dustin
@dustininkster
Apr 27 2016 12:51
function rot13(str) { // LBH QVQ VG!

  return str.split("").map(function (value){
    var offset = 0;
    if (value.charCodeAt(0) > 64 && value.charCodeAt(0) < 78){
      offset = 13;
    } else if (value.charCodeAt(0) > 77 && value.charCodeAt(0) < 91){
      offset = -13;
    }
    return String.fromCharCode(value.charCodeAt(0) + offset);
  }).join('');
}
Is there maybe a better way to go about this?
Paul Knight
@pauljohnknight
Apr 27 2016 12:52
@SekharKolli Thanks. I did that and it worked. I was deleting the console.log not commenting it out - perhaps that was the problem.
CamperBot
@camperbot
Apr 27 2016 12:52
pauljohnknight sends brownie points to @sekharkolli :sparkles: :thumbsup: :sparkles:
:star: 294 | @sekharkolli | http://www.freecodecamp.com/sekharkolli
Sameer Shamsudeen
@sameershamsudheen
Apr 27 2016 12:56
help falsy bouncer
CamperBot
@camperbot
Apr 27 2016 12:56

:point_right: algorithm falsy bouncer [wiki]

Problem Explanation:

Remove all falsy values from an array.

:pencil: read more about algorithm falsy bouncer on the FCC Wiki

Paul Knight
@pauljohnknight
Apr 27 2016 12:57

I've hit my first javascript wall ! All the exercises seemed straightforward, then I came to this and it's like I'm reading a completely new language. I don't know where to start. Should I be using the .push() method. I'm lost.

https://www.freecodecamp.com/challenges/stand-in-line

Hanan Mufti
@h-ARTS
Apr 27 2016 12:57
im testing this functio n and i want to return the arr[x]
function largestOfFour(arr) {
  // You can do this!
  for (var x = 0; x < arr; x++) {
    return arr[x];
  }

}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
now i tried something like this but i can't return it :worried:
function largestOfFour(arr) {
  // You can do this!
  for (var x = 0; x < arr; x++) {
    var value = arr[x];
    for (var y = 0; y < value; y++) {
      var largest = [];
      largest = Math.max(value[y]);
    }
  }

}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Sekhar Kolli
@SekharKolli
Apr 27 2016 13:00
@h-ARTS , first change that you want to make is add the arr.length to the for loop like this for (var x=0; x < arr.length; x++), so you can traverse the array
Dustin
@dustininkster
Apr 27 2016 13:01
@h-ARTS return immediately leaves the method with the result. What you have here will leave with the first x from your loop... thereby exiting the loop as well.
Hanan Mufti
@h-ARTS
Apr 27 2016 13:03
@SekharKolli thx
CamperBot
@camperbot
Apr 27 2016 13:03
h-arts sends brownie points to @sekharkolli :sparkles: :thumbsup: :sparkles:
:star: 295 | @sekharkolli | http://www.freecodecamp.com/sekharkolli
Hanan Mufti
@h-ARTS
Apr 27 2016 13:03
function largestOfFour(arr) {
  // You can do this!
  for (var x = 0; x < arr.length; x++) {
    for (var y = 0; y < arr[x].length; y++) {
      var largest = [];
      largest = Math.max(arr[x][y]);
      return largest;
    }
  }
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
now i can return only "4"
Sekhar Kolli
@SekharKolli
Apr 27 2016 13:04
@h-ARTS , to help you visualize the data better and see what your variables, you might want to add console.log(<variable-name>); throught out your code and see its values in the console window of the browser
Hanan Mufti
@h-ARTS
Apr 27 2016 13:04
@SekharKolli thx i forgot that terribly
CamperBot
@camperbot
Apr 27 2016 13:04
h-arts sends brownie points to @sekharkolli :sparkles: :thumbsup: :sparkles:
:warning: h-arts already gave sekharkolli points
Hanan Mufti
@h-ARTS
Apr 27 2016 13:07
@SekharKolli It's returning all the numbers :worried: But i want to return the largest number with Math.max()?
Stephen James
@sjames1958gm
Apr 27 2016 13:08
@h-ARTS If you only pass Math.max one parameter it will always return that parameter
Blauelf
@Blauelf
Apr 27 2016 13:09
@h-ARTS Do not return from inside the loop. You could use something like largest = Math.max(largest, arr[x][y]);inside the loop, but initialize largest in the outer, not in the inner loop, you want to run that initialization once per iteration of the outer loop, before you enter inner loop. However, I find an if statement more clear, as you don't have to assign if arr[x][y] is not greater than largest.
Sekhar Kolli
@SekharKolli
Apr 27 2016 13:09
@h-ARTS , so what you see is correct. Math.max() is not your solution here. You want to use ‘if' and a comparision operator like ‘>’ ‘<‘ to determine the largest value
Philip Linghammar
@xapax
Apr 27 2016 13:10
Anyone here that has been using gulp?
Sekhar Kolli
@SekharKolli
Apr 27 2016 13:11
@h-ARTS , or you could use it Math.max.apply(null, numArray); as per the example listed here :
Hanan Mufti
@h-ARTS
Apr 27 2016 13:12
thats what I tried before but it returns
TypeError: CreateListFromArrayLike called on non-object
Dustin
@dustininkster
Apr 27 2016 13:12
If you want to use max you'd be better off ditching the second loop I think. There's a way to pull a max straight from an array.
Sekhar Kolli
@SekharKolli
Apr 27 2016 13:13
@h-ARTS , as @dustininkster says, eliminate the second loop;
Blauelf
@Blauelf
Apr 27 2016 13:13

ES5 requires you to write

Math.max.apply(null, numArray)

while ES6 has spread operator, which looks nicer:

Math.max(...numArray)
Dustin
@dustininkster
Apr 27 2016 13:13
var arr = [1, 2, 3];
var max = Math.max(...arr);