These are chat archives for FreeCodeCamp/HelpJavaScript

27th
Mar 2017
Dmytro Holysh
@dmk1111
Mar 27 2017 00:01
@www-leafie-io user actually can change example.com/#!/user/main to example.com/#!/admin/main in address line. So I want to block #!/admin/ for user with 'user' role
Leafie Tutoring
@www-leafie-io
Mar 27 2017 00:01
@dmk1111 you would have to check if they are authenticated in the session
nsonhouse
@nsonhouse
Mar 27 2017 00:05
Hello all
need a little help
Joseph
@revisualize
Mar 27 2017 00:05
With?
Stephen James
@sjames1958gm
Mar 27 2017 00:05
@nsonhouse Ask away
nsonhouse
@nsonhouse
Mar 27 2017 00:06
I need to put a countdown timer on a quiz
Stephen James
@sjames1958gm
Mar 27 2017 00:06
@nsonhouse And . . .
nsonhouse
@nsonhouse
Mar 27 2017 00:06
I have the quiz working fine, but have not figured out how to use the setTimeout correctly
Stephen James
@sjames1958gm
Mar 27 2017 00:07
@nsonhouse What have you tried?
nsonhouse
@nsonhouse
Mar 27 2017 00:08
I have created function and I pass the seconds and the element where I want to the clock to appear
The quiz needs to end when the timer hits 0, but it does not.
The user is till able to answer the remaing questions
Stephen James
@sjames1958gm
Mar 27 2017 00:10
@nsonhouse How are you expecting to stop the user? the setTimer timeout will be asynchronous
Dmytro Holysh
@dmk1111
Mar 27 2017 00:11
@www-leafie-io should this work out?
function loginController($http, $state) {
    let self = this;
    self.loginErrorMessage = false;
    self.username = '';
    self.password = '';
    self.user = '';

    self.logIn = function () {
        var data = {
        username: self.username,
        password: self.password
    };
        $http.post('/api/login', data,
            {headers: {
                'x-requested-with': 'XMLHttpRequest'
                }
            }
        ).then(function (res) {
            self.user = res.data;
               if (self.user.role === 'student') {
            $state.go('student');
              } else if (self.user.role === 'admin') {
            $state.go('admin') }
        }, function (err) {
            self.loginErrorMessage = true;
        });
    }
}

loginController.$inject = ['$http', '$state'];

module.exports = loginController;
Chris
@bestintown23
Mar 27 2017 00:11
How do I use the mouse over function in javascript to stop my slideshow
nsonhouse
@nsonhouse
Mar 27 2017 00:12
@sjames1958gm Please elaborate.
Stephen James
@sjames1958gm
Mar 27 2017 00:13
@nsonhouse How are you expecting the stop the user from answering more questions. Do you go to a completion page or something else?
@nsonhouse It is going to be difficult without a link to the code, or at least some of the code.
nsonhouse
@nsonhouse
Mar 27 2017 00:15

function countDown(secs, elem)
{

            var element = document.getElementById(elem);
            element.innerHTML = "You have " + secs + " seconds left";
            if(secs < 1) 
            {

                clearTimeout(timer);
                element.innerHTML = '<h2>Test is Complete!</h2>';

            }

            secs--;
            var timer = setTimeout('countDown('+secs+',"'+elem+'")',1000);

    }        

    countDown(15,"clock");



    function returnID(x){

            return document.getElementById(x);
    }



    function showQuestion()
    {

        test = returnID("test");
        if(position >= questions.length)
        {
            test.innerHTML = "<h2> You have "+correct+" of "+questions.length+" questions correct</h2>";
            returnID("testStatus").innerHTML = "Test Complete";
            position = 0;
            correct = 0;
            return false;
        }


        returnID("testStatus").innerHTML = "Question " + (position+1)+ " of " + questions.length;
        question = questions[position][0];
        choiceA  = questions[position][1];
        choiceB  = questions[position][2];
        choiceC  = questions[position][3];
        choiceD  = questions[position][4];

        test.innerHTML = "<h3>" + question + "</h3>"; 
        test.innerHTML += "<input type='radio' name='choices' value='A'> " +choiceA+"<br>";
        test.innerHTML += "<input type='radio' name='choices' value='B'> " +choiceB+"<br>";
        test.innerHTML += "<input type='radio' name='choices' value='C'> " +choiceC+"<br>";
        test.innerHTML += "<input type='radio' name='choices' value='D'> " +choiceD+"<br><br>";
        test.innerHTML += "<button onclick = 'checkAnswer()'>Submit Answer</button>";


    }



    function checkAnswer()
    {
            choices = document.getElementsByName("choices");
            for(var i=0; i<choices.length; i++)
            {
                if(choices[i].checked)
                {
                    choice = choices[i].value;
                }
            }

                if(choice == questions[position][5])
                {
                    correct++;
                }
                else{

                }

            position++;
            showQuestion();
    }

window.addEventListener("load", showQuestion, false);

Stephen James
@sjames1958gm
Mar 27 2017 00:16
@nsonhouse When the timer expires you could set a flag that tells submit answer to not process anymore clicks?
Leafie Tutoring
@www-leafie-io
Mar 27 2017 00:17
@dmk1111 i dunno you would have to test it
nsonhouse
@nsonhouse
Mar 27 2017 00:18
@sjames1958gm So when the clock hits 0, disable the button?
Dmytro Holysh
@dmk1111
Mar 27 2017 00:18
@www-leafie-io kk, will try
Lee
@eightlimbs
Mar 27 2017 00:29

how can i declare a local variable "myVar" inside "myLocalScope"?

function myLocalScope() {
'use strict';

console.log(myVar);
}
myLocalScope();

nsonhouse
@nsonhouse
Mar 27 2017 00:31
@sjames1958gm What about calling the countdown function with the onload function?
David Hart
@hart143
Mar 27 2017 00:32
i've been stuck on this one for a while, any suggestions?
David Rowan III
@rowanD72
Mar 27 2017 00:33
hello everyone
David Hart
@hart143
Mar 27 2017 00:33
function largestOfFour(arr) {
  // You can do this!
  var myArr = [];
  var subArr = [];
  for (var i = 0; i < arr.length; i++) { 
    var large = 0;
    subArr = arr.slice(i,i + 1);
    large = Math.max(subArr);
    myArr.push(large);
  }
  return myArr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
David Rowan III
@rowanD72
Mar 27 2017 00:34
I need a little help understanding some simple parts of javascript.
David Hart
@hart143
Mar 27 2017 00:35
@rowanD72 whats your question
David Rowan III
@rowanD72
Mar 27 2017 00:36
nested functions are very confusing to me @hart143
well should I say functions are kind of confusing to me. I really don't fully understand them.
I understand that a function is used to make the code perform some action
I know how to write a function but when it comes to seeing the flow of the function I get confused
David Hart
@hart143
Mar 27 2017 00:38
functions do something, they are called. information can be passed to them or they can just do something, they can return a value
well what's going on in the function?
David Rowan III
@rowanD72
Mar 27 2017 00:39
it's no particular function in question, it's how do I learn the flow of the function. Kind of hard to explain.
silver537
@silver537
Mar 27 2017 00:40
should handle words without vowels?
wtf
David Rowan III
@rowanD72
Mar 27 2017 00:40
maybe I am making understanding functions harder than needs to be
David Hart
@hart143
Mar 27 2017 00:40
the flow... a function starts at the top and flows to the bottom
anyone got any ideas why i am getting "null, null, null, null?
function largestOfFour(arr) {
  // You can do this!
  var myArr = [];
  var subArr = [];
  for (var i = 0; i < arr.length; i++) { 
    var large = 0;
    subArr = arr.slice(i,i + 1);
    large = Math.max(subArr);
    myArr.push(large);
  }
  return myArr;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
Seth
@sethdcd
Mar 27 2017 00:44
how would i target a: 1 in the first object of this array? [{ "a": 1, "b": 3 }, { "a": 1 }, { "a": 1, "b": 2, "c": 2 }]
Manish Giri
@Manish-Giri
Mar 27 2017 00:45
@sethdcd you know the array index, and you know the property name..
try it out
Jason Luboff
@JLuboff
Mar 27 2017 00:45
@hart143 large = Math.max(subArr); This line doesn't work, subArr is a multi-demension array
@hart143 You have [[4,5,1,3]] for instances. You can get it to work though..
David Rowan III
@rowanD72
Mar 27 2017 00:46
ok @hart143
Lee
@eightlimbs
Mar 27 2017 00:47
I am looking for some help with the "Stand in Line" challenge

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

Jason Luboff
@JLuboff
Mar 27 2017 00:47
@eightlimbs You need to use two array methods you recently learned about (pop,push, unshift, shift). Review those challenges and determine which two to use
Stephen James
@sjames1958gm
Mar 27 2017 00:48
@nsonhouse Don't you need somehow to stop the user input once the timer expires
nsonhouse
@nsonhouse
Mar 27 2017 00:49
@sjames1958gm yes sir
Lee
@eightlimbs
Mar 27 2017 00:49
i'll try pop and shift @JLuboff
Stephen James
@sjames1958gm
Mar 27 2017 00:50
@nsonhouse So once the timer expires, you should stop accepting input and going to the next question.
David Rowan III
@rowanD72
Mar 27 2017 00:50
so are global var good or bad?
Stephen James
@sjames1958gm
Mar 27 2017 00:50
@rowanD72 Generally they are to be avoided.
Jason Luboff
@JLuboff
Mar 27 2017 00:50
@eightlimbs shift is correct, but pop is not
David Rowan III
@rowanD72
Mar 27 2017 00:50
ok
David Hart
@hart143
Mar 27 2017 00:51
@JLuboff i was able to get the slice to return 4,5,1,3 (for example) and was able to use max to return 5 (for example) on w3schools, so why doesn't it work now?
Lee
@eightlimbs
Mar 27 2017 00:51
push
nsonhouse
@nsonhouse
Mar 27 2017 00:51
@sjames1958gm I am unaware of how to do this. I either want to disable the button or make it disappear. I am not sure how to set the Boolean value to a button that is being written dynamically.
David Rowan III
@rowanD72
Mar 27 2017 00:51
I just a lot of examples that have global variables. Maybe they're used for teaching purposes only
Stephen James
@sjames1958gm
Mar 27 2017 00:51
@hart143 to get max to work on an array you need Math.max.apply(null, arr[i]);
Jason Luboff
@JLuboff
Mar 27 2017 00:51
@hart143 slice is not returning 4,5,1,3 Its returning [[4,5,1,3]]
David Rowan III
@rowanD72
Mar 27 2017 00:51
*I just see a lot...
Jason Luboff
@JLuboff
Mar 27 2017 00:51
@eightlimbs Correct
Stephen James
@sjames1958gm
Mar 27 2017 00:52
@nsonhouse Give the button an id or class and then set the display to none
Lee
@eightlimbs
Mar 27 2017 00:53
@JLuboff, so what would return item; be changed to ?
Stephen James
@sjames1958gm
Mar 27 2017 00:53
@hart143 you can use arr[i] to get the element
Seth
@sethdcd
Mar 27 2017 00:53
@Manish-Giri ah! i asked that wrongly haha.. what i'm trying to achieve is looping through this array and pulling out each of the values. so yes it'd be nice and easy if i just needed one of the values, but would it be the same thing? Objects.keys gives me 0,1,2 so i'm not sure how to narrow it down
David Hart
@hart143
Mar 27 2017 00:54
@sjames1958gm man that worked but why doesn't the slice work :-(
@sjames1958gm thanks!
CamperBot
@camperbot
Mar 27 2017 00:54
hart143 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 6368 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Stephen James
@sjames1958gm
Mar 27 2017 00:54
@hart143 Because of what @JLuboff says slice gives [[4, 5, 1, 3]] where arr[i] is only [4, 5, 1, 3]
Jason Luboff
@JLuboff
Mar 27 2017 00:54
@eightlimbs Well keep in mind the when you use shift on an array, it returns the element that it removes from the array
Seth
@sethdcd
Mar 27 2017 00:55
@Manish-Giri collections is the parameter/argument collection[0][Object.keys(collection[0])] i was thinking something like this
Manish Giri
@Manish-Giri
Mar 27 2017 00:55
@sethdcd you could first loop through the array, then each element in the array will be an object, since you already know the object properties, you could get their values easily with something like arr[i].a
David Hart
@hart143
Mar 27 2017 00:55
@JLuboff thanks!
CamperBot
@camperbot
Mar 27 2017 00:55
hart143 sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 1287 | @jluboff |http://www.freecodecamp.com/jluboff
Jason Luboff
@JLuboff
Mar 27 2017 00:55
@hart143 slice could work...but you would need to have Math.max.apply(null, subArr[0]); Which really is just an extra unneeded step
Stephen James
@sjames1958gm
Mar 27 2017 00:56
@JLuboff Not just extra, and not just unneeded but extra uneeded :)
Jason Luboff
@JLuboff
Mar 27 2017 00:56
:joy:
David Hart
@hart143
Mar 27 2017 00:56
thanks guys
Jason Luboff
@JLuboff
Mar 27 2017 00:57
@sjames1958gm I was making sure I got my point across :D
Lee
@eightlimbs
Mar 27 2017 00:58
item.push();
i don't know what to type in between the ()
Jason Luboff
@JLuboff
Mar 27 2017 01:01
item is what you want to be pushing. You need to tell it the array to push the item into though
Lee
@eightlimbs
Mar 27 2017 01:04
testArr.push(item);
Jason Luboff
@JLuboff
Mar 27 2017 01:05
arr since thats the parameter from the function
Fabusuyi David Oluwasegun
@dav4thevid
Mar 27 2017 01:06
currently stuck with #Using Objects for Lookups

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

  // Only change code below this line
  var lookup;
  lookup(val="Adams");{result = "alpha";}
  (val = "Boston"); {result = "bravo";}
  (val = "Chicago"); {result = "charlie";}
  (val = "Denver");{result = "delta";}
  (val = "Easy"); {result = "Echo";}
  (val = "Frank"); {result = "foxtrot";}



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

// Change this value to test
phoneticLookup("charlie");
pls help anyone
Manish Giri
@Manish-Giri
Mar 27 2017 01:08
um
you should probably redo the objects lesson
@dav4thevid
Fabusuyi David Oluwasegun
@dav4thevid
Mar 27 2017 01:09
i think so........ma brains aint working well more....its 2:08am here
guess i need a break
Aaron Fox
@aaronfox
Mar 27 2017 01:09
@dav4thevid an object is in the form
var lookup = {
    "a": "hello",
    "b": "world",
  };
and, for example, to return the value "hello", you would return lookup["a"]
herunan
@herunan
Mar 27 2017 01:13

Hi all, I’m on this challenge: https://www.freecodecamp.com/challenges/caesars-cipher

function rot13(str) {
  var arr = str.toUpperCase().split('');
  var unicodeArr = [];
  for (var i=0; i < arr.length; i++) {
    if (arr[i].charCodeAt() > 64 && arr[i].charCodeAt() < 91); {
      unicodeArr.push(arr[i].charCodeAt()+13)
    }
  }
  console.log(unicodeArr);
}

rot13("SERR PBQR PNZC”);

Unfortunately this still adds 13 to non-alphabetic characters (e.g. spaces).

Hernan Mendez
@hernanmendez
Mar 27 2017 01:14
why this cuts up the first 2 characters instead of the first one
function translatePigLatin(str) {
switch (str[0]){
case "a":
case "e":
case "i":
case "o":
case "u":
return str+"way";
}
var substr="";
for (var u=0; u<str.length;u++){
if(str[u] == "a" || str[u] == "e" || str[u] == "i" || str[u] == "o" || str[u] == "u")
{
break;
}
substr+=str[u];
str = str.substr(1);}
return str;
}
@herunan try console.log on the array first to see if everything is ok
herunan
@herunan
Mar 27 2017 01:24
@hernanmendez Indeed, everything seems fine
Hernan Mendez
@hernanmendez
Mar 27 2017 01:26
@herunan i think i know why, it's because the str length changes
how do i declare a constant?
Eric Long
@ejlong90
Mar 27 2017 01:28

Hey, I am on the "Selecting from many options with Switch Statements" section of javascript and I am pretty confused.

It is asking me to Write a switch statement which tests val and sets answer for the following conditions:
1 - "alpha"
2 - "beta"
3 - "gamma"
4 - "delta"

But I am confused on what statements we are supposed to use when the result of expression matches. This is what i have so far, not much


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

 }


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

// Change this value to test
caseInSwitch(1);
Hernan Mendez
@hernanmendez
Mar 27 2017 01:31
now i have no idea
even with a constant
i think is a bug?
DJToners
@DJToners
Mar 27 2017 01:34
yo
how do i share whats on my screen so you can see what i need help with
herunan
@herunan
Mar 27 2017 01:35
@hernanmendez I see what you mean! I just need to add 13 to all alphabetic characters and pass non-alphabetic characters.
@Do you think .map() method would work better?
Gulsvi
@gulsvi
Mar 27 2017 01:37
@DJToners Put your code between backticks https://forum.freecodecamp.com/t/markdown-code-formatting/18391
Hernan Mendez
@hernanmendez
Mar 27 2017 01:37
@herunan i just added another variable and decided to not mess around with str
JamesVitaly
@JamesVitaly
Mar 27 2017 01:38
come this is not returning a whole number
Math.floor(Math.random() * 9);
how*
Sean McDaniel
@SeanMcDaniel1
Mar 27 2017 01:39
Why doesnt this convert the value ?
JamesVitaly
@JamesVitaly
Mar 27 2017 01:39
well I just need to return a whole number it it keeps produing a decimal but i was sure math.floor converted to a whole number
in fact that is the challenge
Gulsvi
@gulsvi
Mar 27 2017 01:39
@JamesVitaly That should give a whole number, is there more code to show?
JamesVitaly
@JamesVitaly
Mar 27 2017 01:40

var randomNumberBetween0and19 = Math.floor(Math.random() * 20);

function randomWholeNum() {

Math.floor(Math.random() * 10);

return Math.random();
}

Moisés Man
@moigithub
Mar 27 2017 01:40
ur function returning something else
not math.floor result
Gulsvi
@gulsvi
Mar 27 2017 01:40
@JamesVitaly You are returning Math.random() not Math.floor(Math.random() * 10);
Ken Haduch
@khaduch
Mar 27 2017 01:40
@JamesVitaly - you should save your value from the Math.floor() or directly return it, do not do the additional Math.random()
JamesVitaly
@JamesVitaly
Mar 27 2017 01:40
ok i see! thanks, kind of weird because that was already there as part of the challenge marked not to edit haha ill change it and see
thanks @khaduch and @SkyCoder01
CamperBot
@camperbot
Mar 27 2017 01:41
jamesvitaly sends brownie points to @khaduch and @skycoder01 :sparkles: :thumbsup: :sparkles:
:cookie: 703 | @skycoder01 |http://www.freecodecamp.com/skycoder01
:star2: 2684 | @khaduch |http://www.freecodecamp.com/khaduch
Hernan Mendez
@hernanmendez
Mar 27 2017 01:42
@ejlong90 what goes betew
@ejlong90 what goes between the switch parameters "()" is val and the cases should be the possibles values of val
@ejlong90 remenber to always use break; at the end of each case
Eric Long
@ejlong90
Mar 27 2017 01:44
So are they asking me to use a random statement for each case? @hernanmendez
Hernan Mendez
@hernanmendez
Mar 27 2017 01:44
@ejlong90 switch (val){
case 1 :
Victoria Zambrano
@vzambrano98
Mar 27 2017 01:44
has anyone been having issues with codepen and bootstrap?
Hernan Mendez
@hernanmendez
Mar 27 2017 01:45
@ejlong90 keep calm and just search for switch on javascript in google if you have any doubts
Gulsvi
@gulsvi
Mar 27 2017 01:46
@vzambrano98 It works fine - it's just that the Bootstrap that gets added with the Quick Add menu is Bootstrap 4. Bootstrap 3 classes don't all work with Bootstrap 4.
Go to Settings -> CSS and replace the link to bootstrap with this one if you want to use bootstrap 3: https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css
Hernan Mendez
@hernanmendez
Mar 27 2017 01:47
@SkyCoder01 so that's why the well class doesn't work?
Gulsvi
@gulsvi
Mar 27 2017 01:47
@hernanmendez Yes, the well class isn't in Bootstrap 4 :(
Victoria Zambrano
@vzambrano98
Mar 27 2017 01:48
@SkyCoder01 you're a savior! haha thanks so much!
CamperBot
@camperbot
Mar 27 2017 01:48
vzambrano98 sends brownie points to @skycoder01 :sparkles: :thumbsup: :sparkles:
:cookie: 704 | @skycoder01 |http://www.freecodecamp.com/skycoder01
Gulsvi
@gulsvi
Mar 27 2017 01:48
No problem, everyone has been hitting that lately :)
Hernan Mendez
@hernanmendez
Mar 27 2017 01:48
@SkyCoder01 WOW i was dying about why that wasn't working
Joseph
@revisualize
Mar 27 2017 01:48
hey hey.
Gulsvi
@gulsvi
Mar 27 2017 01:49
Hello hello
Hernan Mendez
@hernanmendez
Mar 27 2017 01:49
@SkyCoder01 i think that my brain was turned off while i was writting my last message
Gulsvi
@gulsvi
Mar 27 2017 01:50
@hernanmendez wells are now cards in Bootstrap 4: https://v4-alpha.getbootstrap.com/components/card/#background-variants
That's okay lol
Luis
@electrone901
Mar 27 2017 01:52
palindrome("0_0 (: /-\ :) 0-0") should return true.
can't pass the test
suhaschauhan
@suhaschauhan
Mar 27 2017 01:54

function nextInLine(arr, item) {
// Your code here
arr.push(item);
arr.shift();
return arr; // Change this line
}
nextInLine([2],1);
// 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));

can some1 tell me what to return ? Since the function should return the element that was removed
Manish Giri
@Manish-Giri
Mar 27 2017 01:58
@suhaschauhan arr.shift();
Gulsvi
@gulsvi
Mar 27 2017 01:58
@suhaschauhan The push() method adds one or more elements to the end of an array and returns the new length of the array. The shift() method removes the first element from an array and returns that element.
Manish Giri
@Manish-Giri
Mar 27 2017 01:58
you need to return the value of that
@suhaschauhan
David Amanze
@GodKingShogun
Mar 27 2017 02:01
@Manish-Giri :wave:
suhaschauhan
@suhaschauhan
Mar 27 2017 02:02
ahhh gotcha !! great thanks @Manish-Giri
CamperBot
@camperbot
Mar 27 2017 02:02
suhaschauhan sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 4935 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Mar 27 2017 02:02
@GodKingShogun :wave:
Danny Welstad
@GoonTwo
Mar 27 2017 02:07

someone wanna give me a hint on how to set up the answer to the "Profile Lookup" question in JS basics?

I get how to iterate through the array and select certain properties, just can't figure out how to get it all to work together

Danny Welstad
@GoonTwo
Mar 27 2017 02:09
@revisualize thanks! ill take a look at it and see what I come up with
CamperBot
@camperbot
Mar 27 2017 02:09
dwelstad sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3599 | @revisualize |http://www.freecodecamp.com/revisualize
Uros Tadic
@urketadic
Mar 27 2017 02:13
why is twitch api not working? the link on fcc
Din
@DinShpati
Mar 27 2017 02:13
hey guys i need help with this challenge its called "Make Object Properties Private"
here is what i did

var Bike = function() {

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

this.setGear = function() {
gear += 4;
};

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

};

var myCar = new Car();

var myBike = new Bike();

can someone help pls
Stephen James
@sjames1958gm
Mar 27 2017 02:14
@DinShpati setGear needs a parameter to set the gear value to
Edward John
@eddmecha
Mar 27 2017 02:15
morning guys
Din
@DinShpati
Mar 27 2017 02:15
Like this.setGear = function(value){};
Edward John
@eddmecha
Mar 27 2017 02:15
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch (answer) {
    case 1:
      console.log("alpha");
      break;
    case 2:
      console.log("beta");
      break;
    case 3:
      console.log("gamma");
      break;
    case 4:
      console.log("delta");
      break;

    default:
  }


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

// Change this value to test
caseInSwitch(1);
the above code written
what did i do wrongly?
Din
@DinShpati
Mar 27 2017 02:15
Like this.setGear = function(value){ gear };
Like this.setGear = function(value){ gear += set };
????????????
@sjames1958gm ??????
Joseph
@revisualize
Mar 27 2017 02:18
@eddmecha You shouldn't be console.log Your function needs to return answer and so you need to change the value of answer.
Stephen James
@sjames1958gm
Mar 27 2017 02:19
@DinShpati gear = value
Din
@DinShpati
Mar 27 2017 02:19
ok thanks
ill try it
Ronald Johnson
@ronnieg1988
Mar 27 2017 02:19
function chunkArrayInGroups(arr, size) {
var split = arr.slice(0, size);
  var newArray = [];
  if (arr > size){
    newArray.push(split);
  }
  return newArray;
}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
dont get how to push my split array into a new array
Din
@DinShpati
Mar 27 2017 02:19
@sjames1958gm Thanks it worked
CamperBot
@camperbot
Mar 27 2017 02:19
dinshpati sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 6369 | @sjames1958gm |http://www.freecodecamp.com/sjames1958gm
Ronald Johnson
@ronnieg1988
Mar 27 2017 02:20
function chunkArrayInGroups(arr, size) {
var split = arr.slice(0, size);
  var newArray = [];
  if (arr.length > size){
    newArray.push(split);
  }
  return newArray;
}

chunkArrayInGroups(["a", "b",
Stephen James
@sjames1958gm
Mar 27 2017 02:20
@DinShpati :+1:
Ronald Johnson
@ronnieg1988
Mar 27 2017 02:22
that pushes just the first set of the array in i need to get both so that i have a two-dimensional array
any advise
Danny Welstad
@GoonTwo
Mar 27 2017 02:22
@revisualize Hey, I got it to work after looking at your notes. Just curious if how I did it is the easiest/expected way.
function lookUpProfile(firstName, prop){
// Only change code below this line
for (var i = 0; i < contacts.length; i++) {
  if (firstName === contacts[i].firstName) {
    if (contacts[i].hasOwnProperty(prop)) {
      return contacts[i][prop];
    }
    else {
      return "No such property";
    }
}
}
  return "No such contact";
// Only change code above this line
}
Edward John
@eddmecha
Mar 27 2017 02:24
@revisualize ohh i see so it means i have to use
JamesVitaly
@JamesVitaly
Mar 27 2017 02:25
i am tring to return a random function, i have this code but it is telling me it cannot read property of length

function randomWholeNum(quotes) {

var newQuotes = quotes[Math.floor(Math.random()*quotes.length)];
}

Manish Giri
@Manish-Giri
Mar 27 2017 02:25
@dwelstad yup
JamesVitaly
@JamesVitaly
Mar 27 2017 02:25
return a random string**
\
Edward John
@eddmecha
Mar 27 2017 02:25
answer = "beta"
JamesVitaly
@JamesVitaly
Mar 27 2017 02:25
sorry
Danny Welstad
@GoonTwo
Mar 27 2017 02:26
@Manish-Giri thanks!
CamperBot
@camperbot
Mar 27 2017 02:26
dwelstad sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 4937 | @manish-giri |http://www.freecodecamp.com/manish-giri
KatieCz
@KteCz77
Mar 27 2017 02:27
working on the converting celcisus to fahrenheit step. i get the formulas right one at a time but don't understand how to get them all checked off to move on. can anyone explain?
Joseph
@revisualize
Mar 27 2017 02:27
@eddmecha yes
Edward John
@eddmecha
Mar 27 2017 02:27
@revisualize ok i try it now
Ronald Johnson
@ronnieg1988
Mar 27 2017 02:28
@JamesVitaly your math.floor is in an array for starters try deleting the [ ]
JamesVitaly
@JamesVitaly
Mar 27 2017 02:29
tried
still not working :(
Emilio Cantón
@Cabemo
Mar 27 2017 02:30

Hey guys, one question: Is it possible to use comparison and logical operators in "switch"?
ex:

case x < 5:

or

case <5:
Luis
@electrone901
Mar 27 2017 02:31
Hi guys, quick question. have anyone tried to check if a string is a palindrome?
Joseph
@revisualize
Mar 27 2017 02:31
@Cabemo Neither.
JamesVitaly
@JamesVitaly
Mar 27 2017 02:31
@ronnieg1988 Yeh i tried changing it out but still no luck, any ideas ?
Emilio Cantón
@Cabemo
Mar 27 2017 02:32
All right, and in general in "switch" I`m guessing it can´t be used @revisualize
Joseph
@revisualize
Mar 27 2017 02:32
@Cabemo If you want to make a comparison or use a logical operator.. You should use an if
Jor
@joreyesl
Mar 27 2017 02:33
@Cabemo you can do it, but its not very intuitive. You could just use if statements.
Emilio Cantón
@Cabemo
Mar 27 2017 02:35
Thanks @joreyesl @revisualize then it was easier with "IF" I guess, some dude told me yesterday it would be better with "switch"
CamperBot
@camperbot
Mar 27 2017 02:35
cabemo sends brownie points to @joreyesl and @revisualize :sparkles: :thumbsup: :sparkles:
:cookie: 681 | @joreyesl |http://www.freecodecamp.com/joreyesl
:star2: 3600 | @revisualize |http://www.freecodecamp.com/revisualize
Ronald Johnson
@ronnieg1988
Mar 27 2017 02:36
function ourRandomRange(quote {

  return Math.floor(Math.random() * (quote.length+ 1)) ;
}
@JamesVitaly maybe try something like this
opps forgot )
JamesVitaly
@JamesVitaly
Mar 27 2017 02:36
@ronnieg1988 will try now
@ronnieg1988 no luck :(
Manish Giri
@Manish-Giri
Mar 27 2017 02:38
@JamesVitaly what seems to be the problem?
Ronald Johnson
@ronnieg1988
Mar 27 2017 02:38
post the whole code
Jor
@joreyesl
Mar 27 2017 02:38
@JamesVitaly is quotes defined and is it an array?
JamesVitaly
@JamesVitaly
Mar 27 2017 02:38

function randomWholeNum(quotes) {

return Math.floor(Math.random() * (quotes.length+ 1));
}
var quotes = ["I had nothing to offer anybody except my own confusion.", "We are here to laugh at the odds and live our lives so well that Death will tremble to take us.","Your mind will answer most questions if you learn to relax and wait for the answer.","We are what we pretend to be, so we must be careful about what we pretend to be."];

yeh
Jor
@joreyesl
Mar 27 2017 02:39
@electrone901 you can just post your code here rather than the link
Luis
@electrone901
Mar 27 2017 02:39
thanks @joreyesl
CamperBot
@camperbot
Mar 27 2017 02:39
electrone901 sends brownie points to @joreyesl :sparkles: :thumbsup: :sparkles:
:cookie: 682 | @joreyesl |http://www.freecodecamp.com/joreyesl
JamesVitaly
@JamesVitaly
Mar 27 2017 02:39
@Manish-Giri i want to return a random string from an array, I though i came up with a solution but it tells me that length is undefine cannot read it as a property
Luis
@electrone901
Mar 27 2017 02:40
function palindrome(str) {
str = str.toLowerCase();
str = str.replace(/["_", " ", ",", ".", "-", "(", ":", "/", "\", ":", ")" ]/g, '');
newStr = str.split('').reverse().join('');
if(str == newStr) return true;
else return false;
}
palindrome("0_0 (: /-\ :) 0-0");
Manish Giri
@Manish-Giri
Mar 27 2017 02:40
@JamesVitaly can you share your pen link?
Luis
@electrone901
Mar 27 2017 02:41
should return true
JamesVitaly
@JamesVitaly
Mar 27 2017 02:41
Jor
@joreyesl
Mar 27 2017 02:41
@JamesVitaly you have a parameter quotes and also a global array quotes, make sure you are actually passing in an argument to the function otherwise quotes inside the function will be undefined.
Ngo Quoc Hiep
@quochiep87
Mar 27 2017 02:41
how to do?
Do not change code above the line
a should have a value of 7
b should have a value of 7
a should be assigned to b with =
JamesVitaly
@JamesVitaly
Mar 27 2017 02:42
@joreyesl will tak a closer look at that thanks
CamperBot
@camperbot
Mar 27 2017 02:42
jamesvitaly sends brownie points to @joreyesl :sparkles: :thumbsup: :sparkles:
:cookie: 683 | @joreyesl |http://www.freecodecamp.com/joreyesl
Manish Giri
@Manish-Giri
Mar 27 2017 02:43
@JamesVitaly works for me
 function newQuote(quotes) {
 var quote = quotes[Math.floor(Math.random() * quotes.length)];
   console.log(quote);
}
var quotes = ["I had nothing to offer anybody except my own confusion.", "We are here to laugh at the odds and live our lives so well that Death will tremble to take us.","Your mind will answer most questions if you learn to relax and wait for the answer.","We are what we pretend to be, so we must be careful about what we pretend to be."]
newQuote(quotes);
JamesVitaly
@JamesVitaly
Mar 27 2017 02:44
@Manish-Giri how did you test it, I have been trying to test in an random free code camp challenge... thanks for checking haha!
CamperBot
@camperbot
Mar 27 2017 02:44
jamesvitaly sends brownie points to @manish-giri :sparkles: :thumbsup: :sparkles:
:star2: 4939 | @manish-giri |http://www.freecodecamp.com/manish-giri
Manish Giri
@Manish-Giri
Mar 27 2017 02:44
remember to pass the quotes array to the newQuote function, as @joreyesl said
@JamesVitaly
@JamesVitaly I tested by putting a console.log statement - console.log(quote);
JamesVitaly
@JamesVitaly
Mar 27 2017 02:45
@Manish-Giri thanks again and @ronnieg1988 thanks for your help earlier too
CamperBot
@camperbot
Mar 27 2017 02:45
jamesvitaly sends brownie points to @manish-giri and @ronnieg1988 :sparkles: :thumbsup: :sparkles:
:warning: jamesvitaly already gave manish-giri points
:cookie: 249 | @ronnieg1988 |http://www.freecodecamp.com/ronnieg1988
Shikazuka
@Arthareza
Mar 27 2017 02:46
sorry guys can anyone help me with task "create decimal number with javascript"
Roxroy
@roxroy
Mar 27 2017 02:46
@JamesVitaly , now that it is working you can move on to hookup the button click - use jQuery to handle the on click event.
Joseph
@revisualize
Mar 27 2017 02:47
@quochiep87 How do you assign the value of 7 to a variable num? ... var num = 7;
Now if you want you can use a variable to store values.
Like in mathmatics. num + 3 = 10 What is the value of num?
var x = num + 3; ... That outputs 10
So, you can do several things with variables. But, you need to understand that variables hold values and variables can be used with other variables.
So, how do you assign the value of 5 to a variable x? ... x = 5; (Which is also overwriting the previous value of 10 from above.
How do you assign the value of x to a variable y?
Look at the way things are written. var y = x;
How do you assign the value of 42 to a variable answer? ... What is the answer?
Variables hold values. Just understand that.
Jor
@joreyesl
Mar 27 2017 02:47
@electrone901 that looks good but you could use a better regex for the replace method. Try looking at using the character class \W along with a character set [ ]. And you dont need quotes " inside the regex. They will be treated as literals, ex: if i want to match _ and ., I could do /[_.]/g dont need to do /["_","."]/g as you are doing.
Roxroy
@roxroy
Mar 27 2017 02:47
@Arthareza , what part are u stuck with?
JamesVitaly
@JamesVitaly
Mar 27 2017 02:48
@roxroy yeh thats the next step
Roxroy
@roxroy
Mar 27 2017 02:48
@JamesVitaly , show me what u have done so far
JamesVitaly
@JamesVitaly
Mar 27 2017 02:49
Ronald Johnson
@ronnieg1988
Mar 27 2017 02:49
function chunkArrayInGroups(arr, size) {
var split = arr.slice(0, size);
  var newArray = [];
  if (arr.length > size){
    newArray.push(split);
  }
  return newArray;

}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
cant figure out how to add the second array to the newarray
JamesVitaly
@JamesVitaly
Mar 27 2017 02:49
@roxroy just trying to make sure i have passed on my array to the function
Shikazuka
@Arthareza
Mar 27 2017 02:50

@roxroy i don't know how to make the variable mydecimal

mydecimal=5.7;

is this true ?

Roxroy
@roxroy
Mar 27 2017 02:51
@Arthareza , you are missing the var part before mydecimal =....
Luis
@electrone901
Mar 27 2017 02:51
@joreyesl let me try
Jor
@joreyesl
Mar 27 2017 02:51
@ronnieg1988 you will need to use a loop. and slice the array by size chunks. .splice might be better if you want to use the same arguments, otherwise if you want to use .slice you will need to update the range you want to slice
Ronald Johnson
@ronnieg1988
Mar 27 2017 02:51
@joreyesl i did i can return the a and b together but cant return the c and d
Shikazuka
@Arthareza
Mar 27 2017 02:52
@roxroy still not working
Roxroy
@roxroy
Mar 27 2017 02:52
@Arthareza , paste the line here..
Carson Michael
@Carson2003
Mar 27 2017 02:53
can someone please tell me why this isn't working here is my code

//Setup
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["Javascript", "Gaming", "Foxes"]
}
];

function lookUpProfile(firstName, prop){
// Only change code below this line
var checkN = "No such contact";
var checkP = "No such property";

for( i = 0; i < contacts.length; i++){
if (contacts[i].firstName == firstName){
checkN = contacts[i.firstName];
if(contacts[i].hasOwnProperty(prop)){
checkP = contacts[i].prop;

 }

}
}
if (checkN == "No such contact"){
return checkN;
}else{
return checkP;
}
// Only change code above this line
}

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

Shikazuka
@Arthareza
Mar 27 2017 02:53
var mydecimal = 5.7;
Jor
@joreyesl
Mar 27 2017 02:53
@ronnieg1988 yes because you are only slice once, you also need to slice the 2nd half, and if the array they pass in is bigger, then you need to slice some more, and so on. That is why you want to do it in a loop.
Roxroy
@roxroy
Mar 27 2017 02:53
@Arthareza , variable names are case sensitive you need to use myDecimal
Shikazuka
@Arthareza
Mar 27 2017 02:54
@roxroy it's work Thanks
CamperBot
@camperbot
Mar 27 2017 02:54
arthareza sends brownie points to @roxroy :sparkles: :thumbsup: :sparkles:
:cookie: 475 | @roxroy |http://www.freecodecamp.com/roxroy
Ronald Johnson
@ronnieg1988
Mar 27 2017 02:54
so i need another if loop or a different one?
Roxroy
@roxroy
Mar 27 2017 02:55
@Arthareza , NP. There you go. Remember that the mydecimal is not the same as myDecimal or MyDecimal
David Amanze
@GodKingShogun
Mar 27 2017 02:56
can someone tell me why this is return unefined or null reference
return str.match(/[^\d\s()-]/g).length;
Carson Michael
@Carson2003
Mar 27 2017 02:57
need help please
David Amanze
@GodKingShogun
Mar 27 2017 02:58
@Carson2003 with what
Roxroy
@roxroy
Mar 27 2017 02:58
@JamesVitaly , you can use this example
Carson Michael
@Carson2003
Mar 27 2017 02:58
with this

//Setup
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["Javascript", "Gaming", "Foxes"]
}
];

function lookUpProfile(firstName, prop){
// Only change code below this line
var checkN = "No such contact";
var checkP = "No such property";

for( i = 0; i < contacts.length; i++){
if (contacts[i].firstName == firstName){
checkN = contacts[i.firstName];
if(contacts[i].hasOwnProperty(prop)){
checkP = contacts[i].prop;

 }

}
}
if (checkN == "No such contact"){
return checkN;
}else{
return checkP;
}
// Only change code above this line
}

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

it is the profile lookup challenge
JamesVitaly
@JamesVitaly
Mar 27 2017 02:58
@roxroy which example?
David Amanze
@GodKingShogun
Mar 27 2017 02:59
@Carson2003 what specifically do you need help with
Ángel Araya
@angelaraya
Mar 27 2017 02:59
@GodKingShogun null is returned when no match is found. What is the value of str?
Cryptonomy
@Cryptonomy
Mar 27 2017 02:59
Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.
Roxroy
@roxroy
Mar 27 2017 02:59
@JamesVitaly , you can use this example, ]see here
$( "#target" ).click(function() {
  alert( "Handler for .click() called." );
});
Cryptonomy
@Cryptonomy
Mar 27 2017 02:59
I'm confused on this one..
David Amanze
@GodKingShogun
Mar 27 2017 03:00
@angelaraya @angelaraya
telephoneCheck("555-555-5555");
Carson Michael
@Carson2003
Mar 27 2017 03:00
its not returning any properties
Jor
@joreyesl
Mar 27 2017 03:00
@Carson2003 you need to fix this line contacts[i.firstName]; and also this one contacts[i].prop;.
remember contacts[i] is the object you are looking at, and prop is a variable so you can't use dot notation, you have to use bracket notation.
Cryptonomy
@Cryptonomy
Mar 27 2017 03:00
Tried different combinations of shift and push but not availing here. Any hints/ tips for "Stand in line"
David Amanze
@GodKingShogun
Mar 27 2017 03:00
@Cryptonomy you will have to revisit the section that talks about push and pop an array
Ángel Araya
@angelaraya
Mar 27 2017 03:01
@GodKingShogun well, I think your regex is not looking for numbers, so none is going to be matched
Carson Michael
@Carson2003
Mar 27 2017 03:01
@joreyesl it didn't help
Ángel Araya
@angelaraya
Mar 27 2017 03:01
A rule of thumb for regex is to start simple and then grow from there
Jor
@joreyesl
Mar 27 2017 03:02
@Carson2003 what is the new code? only post the changes, not the whole thing.
Ronald Johnson
@ronnieg1988
Mar 27 2017 03:03
function chunkArrayInGroups(arr, size) {
var split = arr.slice(0, size);
  var splitAgain= arr.slice(2,arr.length);
  var newArray = [];
  if (arr.length > size){
    newArray.push(split);
  }
  if (arr.length > size){
    newArray.push(splitAgain);
  }
  return newArray;

}

chunkArrayInGroups(["a", "b", "c", "d"], 2);
@joreyesl i got it to return both arrays into the new one but it only works for 1 of the objectives
Carson Michael
@Carson2003
Mar 27 2017 03:03
if (contacts[i.firstName] == firstName){
checkN = contacts[i.firstName];
if(contacts[i].hasOwnProperty(prop)){
checkP = contacts[i.prop];
David Amanze
@GodKingShogun
Mar 27 2017 03:03
@angelaraya idu. i know none is going to be matched with that example so the length is going to be 0
but it return undefined or null
which is bad for me
Jor
@joreyesl
Mar 27 2017 03:04
@Carson2003 you want to keep it like contacts[i]. That is the object. then if want the firstName then you want to do contacts[i].firstName. Now for props it will be different because prop is a variable so you have to use bracket notation, like contacts[i][prop]
Ángel Araya
@angelaraya
Mar 27 2017 03:04
@GodKingShogun because String.match() return null when there is no match. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match
David Amanze
@GodKingShogun
Mar 27 2017 03:05
@angelaraya okay. let me build my code around that info
@angelaraya thanks
CamperBot
@camperbot
Mar 27 2017 03:05
godkingshogun sends brownie points to @angelaraya :sparkles: :thumbsup: :sparkles:
:cookie: 297 | @angelaraya |http://www.freecodecamp.com/angelaraya
Chuck Taylor
@cbtaylor2
Mar 27 2017 03:06
Totally lost on the "Word Blanks" challenge. Pls assist.
Carson Michael
@Carson2003
Mar 27 2017 03:06
thanks @joreyesl it worked
CamperBot
@camperbot
Mar 27 2017 03:06
carson2003 sends brownie points to @joreyesl :sparkles: :thumbsup: :sparkles:
:cookie: 684 | @joreyesl |http://www.freecodecamp.com/joreyesl
Jor
@joreyesl
Mar 27 2017 03:06
@Carson2003 :thumbsup:
ivorygrant
@ivorygrant
Mar 27 2017 03:06
hi everyone, working on the profile lookup challenge, i think i'm very close. I'm getting an error on my first if statement if someone can point me the right direction
function lookUpProfile(firstName, prop){
// Only change code below this line

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

    if (contacts[i].firstName==firstName && contacts[i].hasOwnProperty==prop) {
      return firstName, contacts[i].prop; 

    }

    else if(contacts[i].firstName==firstName && contacts[i].hasOwnProperty!=prop) {
      return "No such property";
    }
    else if(contacts[i].firstName!=firstName){
      return "No such contact";
    }
  }
Ángel Araya
@angelaraya
Mar 27 2017 03:07
@cbtaylor2 Hi! What have you tried so far?
Jor
@joreyesl
Mar 27 2017 03:08
@ronnieg1988 yea thats is why i suggested a loop, and as you've noticed the start and end index for slice will change, but they are easy to calculate in terms of i and size.
JamesVitaly
@JamesVitaly
Mar 27 2017 03:08
@roxroy thanks for your help I have to dash off, now ill get to the bottom of thr problem later )
CamperBot
@camperbot
Mar 27 2017 03:08
jamesvitaly sends brownie points to @roxroy :sparkles: :thumbsup: :sparkles:
:cookie: 476 | @roxroy |http://www.freecodecamp.com/roxroy
Roxroy
@roxroy
Mar 27 2017 03:09
@JamesVitaly , catch you later
Cryptonomy
@Cryptonomy
Mar 27 2017 03:10
@GodKingShogun I went and looked back at everything and it's still not clicking with me how to go about this.
Joseph
@revisualize
Mar 27 2017 03:10
@ivorygrant Your for loop isn't looping.
Roxroy
@roxroy
Mar 27 2017 03:10
@ivorygrant , the issue is with contacts[i].hasOwnProperty==prop The hasOwnProperty() method returns a boolean indicating whether the object has the specified property.
eg o.hasOwnProperty('prop'); // returns true
kailasa8055
@kailasa8055
Mar 27 2017 03:10
Screenshot (7).png
Chuck Taylor
@cbtaylor2
Mar 27 2017 03:10

i keep getting an error message on "Word Blanks" challenge. Please Help.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");

kailasa8055
@kailasa8055
Mar 27 2017 03:10
how do iterate through the array when it has one dimension and some other times multi dimension?
Joseph
@revisualize
Mar 27 2017 03:10
@kailasa8055 You're doing too much multiplication.
@kailasa8055 Your second loop isn't correct.

@cbtaylor2 Gist by revisualize / FreeCodeCamp - Word_Blanks.js
The function declaration was set up as... function wordBlanks(myNoun, myAdjective, myVerb, myAdverb) giving the function name as wordBlanks and with four parameter of myNoun, myAdjective, myVerb and myAdverb.
There is more that I could go into (if you want I can) but, I'll sum it up with:
Parameters are treated like variables that represent the values that get passed into your function from the function call (arguments).

Here's an example of this:

function hello(fName, uName) {
     return "Hello " + fName + " " + uName + ", How is your day?";
}
hello("Joseph", "@revisualize"); // "Hello Joseph @revisualize, How is your day?"
hello("Bella", "@bellaknoti"); // "Hello Bella @bellaknoti, How is your day?"
hello("Andy", "@dirn"); // "Hello Andy @dirn, How is your day?"

You can use the fName and uName parameters just like a variable inside of your function.

@roxroy @ivorygrant That isn't correct.. Quotes define strings.
Cryptonomy
@Cryptonomy
Mar 27 2017 03:13

function nextInLine(arr, item) {
// Your code here
arr.push();
arr.shift();

return item; // Change this line
}

Joseph
@revisualize
Mar 27 2017 03:13
@Cryptonomy You're not adding anything to the array.
ivorygrant
@ivorygrant
Mar 27 2017 03:13
hmmm let me think about this...are my other conditions correct?
Joseph
@revisualize
Mar 27 2017 03:14
@ivorygrant Was that question for me?
ivorygrant
@ivorygrant
Mar 27 2017 03:15
@revisualize yes
Cryptonomy
@Cryptonomy
Mar 27 2017 03:15
@Joseph Not sure how I'm supposed to go about this
Joseph
@revisualize
Mar 27 2017 03:15
@ivorygrant You have to change your logic. Your loop isn't looping.
@Cryptonomy How do you add an element to the end of an array?
Ronald Johnson
@ronnieg1988
Mar 27 2017 03:16
function chunkArrayInGroups(arr, size) {
var split = arr.slice(0, size);
  var splitAgain= arr.slice(2,arr.length);
  var newArray = [];
  if (arr.length > size){
    newArray.push(split);
  }
  if (arr.length > size){
    newArray.push(splitAgain);
  }
  return newArray;

}

chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3);
@joreyesl this should return 3 arrays [0,1][2,3][4,5] its only returning 2 [0,1,2][2,3,4,5]
ivorygrant
@ivorygrant
Mar 27 2017 03:16
@revisualize so my for statement is incorrect? hmmm
Cryptonomy
@Cryptonomy
Mar 27 2017 03:16
@joseph unshift?
Roxroy
@roxroy
Mar 27 2017 03:16
@revisualize , @ivorygrant is doing the Profile question not the Quote question. The issue is regarding the use of the hasOwnProperty function.
Joseph
@revisualize
Mar 27 2017 03:16
@Cryptonomy Incorrect.
@roxroy I know what @ivorygrant is doing. I've solved that challenge 5 different ways.
Cryptonomy
@Cryptonomy
Mar 27 2017 03:17
@joseph wait, push is supposed to add the beginning to last.
Joseph
@revisualize
Mar 27 2017 03:17
@roxroy I made a comment for @cbtaylor2 then I made a comment for @roxroy and tagged @ivorygrant
@Cryptonomy There is no method that adds the beginning of an array to the end of an array.
Cryptonomy
@Cryptonomy
Mar 27 2017 03:18
Yes, it is. But I'm just not sure how to utilize it properly apparently lol.
ivorygrant
@ivorygrant
Mar 27 2017 03:18
@revisualize hmmm the only think i can think of is to do <= to include all members
Joseph
@revisualize
Mar 27 2017 03:19
@Cryptonomy You should look up the methods that you're trying to use.
Cryptonomy
@Cryptonomy
Mar 27 2017 03:19
".push() takes one or more parameters and "pushes" them onto the end of the array."
Joseph
@revisualize
Mar 27 2017 03:19
@Cryptonomy Okay. What does that method return?
Cryptonomy
@Cryptonomy
Mar 27 2017 03:19
still outputs 12345
Roxroy
@roxroy
Mar 27 2017 03:20
@revisualize , np. It happens at times - especially in an active chatroom like this.
Cryptonomy
@Cryptonomy
Mar 27 2017 03:22
@revisualize still outputs 12345 with arr.push()
Dana Aljirudi
@DanaJirudi
Mar 27 2017 03:23
Hello guys. I'm doing the "Chunky Monkey" algorithm challenge.. I managed to do it when "size" is 2. Any idea on how to make it work for any number?
```
```
Cryptonomy
@Cryptonomy
Mar 27 2017 03:23
Oh, I see. It just appends them to the end of the array @revisualize
Mike Echlin
@mechlin69
Mar 27 2017 03:23
really stuck on challenge 175
Dana Aljirudi
@DanaJirudi
Mar 27 2017 03:23
function chunkArrayInGroups(arr, size) {
  // Break it up.
  var arrNum1 = arr.slice(size);
  var arrNum2 = arr.slice(0, size);
  var slicedArr = [arrNum2].concat([arrNum1]);

  return slicedArr;
}
ivorygrant
@ivorygrant
Mar 27 2017 03:23
@roxroy ok i thought about this. I want to see if contact equals contact, then check if the property exists so that i can return the property
Joseph
@revisualize
Mar 27 2017 03:24
@Cryptonomy What does the .push() method return?
ivorygrant
@ivorygrant
Mar 27 2017 03:24
*return the property value
Dana Aljirudi
@DanaJirudi
Mar 27 2017 03:26
Any idea on how to make the program work when size other than two?
Cryptonomy
@Cryptonomy
Mar 27 2017 03:26
@revisualize it returns 12345, unless I add a number in push ex arr.push(1); since it just appends.
Lee
@eightlimbs
Mar 27 2017 03:27
hey guys i'm stumped on the caseInSwitch challenge
this is what i have...

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

switch (2) {
case "beta":
break;}

switch (3) {
case "gamma":
break;}

switch (4) {
case "delta":
break;}

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

Edward John
@eddmecha
Mar 27 2017 03:27
@eightlimbs you should scroll back up i have just complete it just now
Ronald Johnson
@ronnieg1988
Mar 27 2017 03:28
why so many switchs?
Roxroy
@roxroy
Mar 27 2017 03:28
@ivorygrant , did the update work for you? or do you have a question for me?
Joseph
@revisualize
Mar 27 2017 03:28
@Cryptonomy That's incorrect. You really should look your methods up.
ivorygrant
@ivorygrant
Mar 27 2017 03:29
@roxroy i updated to this, but still no go.
for (i=0; i<=contacts.length; i++) {

    if (contacts[i].firstName==firstName && contacts[i].hasOwnProperty==prop) {
      return firstName +", " + contacts[i].prop; 

    }

    else if(contacts[i].firstName==firstName && contacts[i].hasOwnProperty!=prop) {
      return "No such property";
    }
    else if(contacts[i].firstName!=firstName){
      return "No such contact";
    }
  }
Joseph
@revisualize
Mar 27 2017 03:29
@ivorygrant Okay.
@ivorygrant Let me write something for you.
Roxroy
@roxroy
Mar 27 2017 03:30
@ivorygrant , try else if(contacts[i].firstName==firstName && contacts[i].hasOwnProperty(prop)) {
ivorygrant
@ivorygrant
Mar 27 2017 03:30
ohhhhhhhhhhhhh
i deserve a virtual slap for that!
Lee
@eightlimbs
Mar 27 2017 03:30
@eddmecca I can't find it
Roxroy
@roxroy
Mar 27 2017 03:31
@ivorygrant , you have to tell it what property to check
Joseph
@revisualize
Mar 27 2017 03:32
var value = "e"
var arr = ["a", "b", "c", "d", "e"];
for (var i = 0; i < arr.length; i++) {
      if (value === arr[i]) { return "True"; }
      else if (value !=== arr[i]) { return "False" }
}
@ivorygrant How many times do you think this loop runs?
ivorygrant
@ivorygrant
Mar 27 2017 03:32
4 times
Joseph
@revisualize
Mar 27 2017 03:32
@ivorygrant Incorrect.
Edward John
@eddmecha
Mar 27 2017 03:32

@eightlimbs try this

switch (val) {
    case 1:
      answer = "alpha";
      break;
    case 2:
      answer = "beta";
      break;
    case 3:
      answer = "gamma";
      break;
    case 4:
      answer = "delta";
      break;

u only need to use switch once

Ronald Johnson
@ronnieg1988
Mar 27 2017 03:32
5 times
Joseph
@revisualize
Mar 27 2017 03:33
@ronnieg1988 Incorrect.
Ronald Johnson
@ronnieg1988
Mar 27 2017 03:33
really>
Joseph
@revisualize
Mar 27 2017 03:33
Really.
Edward John
@eddmecha
Mar 27 2017 03:33
and what you wanted it to switch is the value not the answer
Lee
@eightlimbs
Mar 27 2017 03:33
ahhh... thanks @eddmecha !!
CamperBot
@camperbot
Mar 27 2017 03:33
eightlimbs sends brownie points to @eddmecha :sparkles: :thumbsup: :sparkles:
:warning: @eddmecha's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
Ronald Johnson
@ronnieg1988
Mar 27 2017 03:34
the array length is 5 tho
Joseph
@revisualize
Mar 27 2017 03:34
@ronnieg1988 So.
Ronald Johnson
@ronnieg1988
Mar 27 2017 03:34
arr.length = 5
Joseph
@revisualize
Mar 27 2017 03:34
Correct.
ivorygrant
@ivorygrant
Mar 27 2017 03:34
@revisualize well i can guess once, but i don't know why
Roxroy
@roxroy
Mar 27 2017 03:34
@revisualize , just once ---> returns false
Joseph
@revisualize
Mar 27 2017 03:34
@ivorygrant Let's walk you through it.
Chris Cullen
@123xylem
Mar 27 2017 03:35

Why are my flash messages always showing and acting like functions?
Here I defind error and success..

app.use(function(req,res,next){                                  
    res.locals.currentUser=req.user;                              //Looks in the requests local properties for req.user which gets stored in currentuser var

    //===================================Flash messages below. if  error or sucess is stored in flash make them equal to res.locals.error/sucess
    res.locals.error=flash("error");
    res.locals.success=flash("success");
    next();                                                        //then it allows the route to continue
});

Here i use it in a route middleware.. so when your not logged in it shows a message.

middlewareObj.isLoggedIn = function(req, res, next){
    if(req.isAuthenticated()){
        return next();
    }
    req.flash("error", "You need to be logged in to do that");
    res.redirect("/login");
}

And here i include it in my site via the header.. If the message exists and has more than 0 characters in it show it- else dont- But its just showing the function of the header instead.

<!--//==================================Flash Messages=================-->
  <div class="container">

        <% if(error && error.length > 0){
        console.log(error,error.length)%>
            <div class="alert alert-danger" role="alert">
                <%= error %>
            </div>
        <% } %>
        <% if(success && success.length > 3){ %>
            <div class="alert alert-success" role="alert">
                <%= success %>
            </div>
        <% } %>
    </div>

THe console.log shows function, 3
Any idea why the flash message is shwing as a function all the time and not waiting for the message to trigger?

Ronald Johnson
@ronnieg1988
Mar 27 2017 03:36
oh lol i didnt read the rest of it i just read the for loop
Cryptonomy
@Cryptonomy
Mar 27 2017 03:36
@revisualize I just looked it up. I'd been on that for quite a while, and was burnt out on it. I didn't know I could put it the two arguments in the push. If I would've known that it would have been a walk in the park.

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

  return arr.shift();  // Change this line
}
Joseph
@revisualize
Mar 27 2017 03:37
var value = "e"
var arr = ["a", "b", "c", "d", "e"];
for (var i = 0; i < arr.length; i++) {
     // at the first iteration i is 0
     // arr[i] is arr[0] and arr[0] holds the value of "a"
     // if ("e" === "a") ... return "True" ... Well, "e" is not "a" so, no.
      if (value === arr[i]) { return "True"; }
     // okay so nest block
     // if "e" is not equal to "a" ... that's true ... so ... return "False"
      else if (value !=== arr[i]) { return "False" }
}
@ivorygrant
ivorygrant
@ivorygrant
Mar 27 2017 03:38
ok i follow, it only runs once
Joseph
@revisualize
Mar 27 2017 03:38
@ivorygrant Look at what you're doing with your Profile Lookup code.
@ivorygrant Your loop is NOT looping.
ivorygrant
@ivorygrant
Mar 27 2017 03:40
ahh ok perhaps my error is the order of my arguments
since it checks the first one and doesn't find it, it stops
Ronald Johnson
@ronnieg1988
Mar 27 2017 03:43
function chunkArrayInGroups(arr, size) {
var split = arr.slice(0, size);
  var splitAgain= arr.slice(size ,arr.length);
  var newArray = [];
  if (arr.length > size){
    newArray.push(split);
  }
  if (arr.length > size){
    newArray.push(splitAgain);
  }
  return newArray;

}

chunkArrayInGroups([0, 1, 2, 3, 4, 5], 3);
it returns 2 arrays but when i need 3 it only returns 2
Aaron Bell
@awb715
Mar 27 2017 03:43
does anyone know how to access a variable in the document object in jquery?
Roxroy
@roxroy
Mar 27 2017 03:44
@ivorygrant , the problem is that every one of your if/else has a return. And as such the whole 'for loop' is executed just once. It never goes to check the next name in the array. Check your if/else conditions
David Amanze
@GodKingShogun
Mar 27 2017 03:46
its been nice knowing all of you. ill go jump off a building now :smile:

function telephoneCheck(str) {
  // Good luck!
  var strikes=0;
  var digit= /\d/g;
  var allow= /[^\d\s()-]/;
  if (str.match(allow)===null) {

  } else{     
    strikes++;

    }
  if (str.indexOf("-")===0){
    strikes++;
    console.log(strikes);
  }
  if (str[0]==="1"&&str.match(digit).length!==11) {
    strikes++;
  } 
  if (str[0]!=="1"&& str.match(digit).length!==10){
     strikes++;
  } 
  if (/[()]/.test(str)===true){
    if (str.indexOf("(")===1||str.indexOf("(")===2||str.indexOf("(")===0&&str.indexOf(")")===5||str.indexOf(")")===6||str.indexOf(")")===4){

    } else {
        strikes++;
      console.log(strikes);
    }
  }


  if (strikes===0){
    return true;
  } else {
    return false;
  }
}
ivorygrant
@ivorygrant
Mar 27 2017 03:47
@roxroy My initial reaction is to create separate for loops for each situation but that seems repetitive
Kaue Rodrigo Pacheco
@kauepacheco
Mar 27 2017 03:49

function titleCase(str) {

  lowerCase = str.toLowerCase();

  var arr = lowerCase.split(" ");

  for (var i = 0; i < arr.length; i++) {
    upperCase = arr[i][0].toUpperCase() + arr[i];
    console.log(upperCase);
  }
}

titleCase("I'm a little tea pot");
How do I remove the first letter of arr[i]?
output:
Ii'm
Aa
Llittle
Ttea
Ppot
Chuck Taylor
@cbtaylor2
Mar 27 2017 03:50
I'm trying the suggestions from joseph@revisualize.
Jor
@joreyesl
Mar 27 2017 03:51
@kauepacheco you need to make a new string, try lookin at substring()
ivorygrant
@ivorygrant
Mar 27 2017 03:56
ok after some i thought i declared a local variable answer and to return the answer
var answer;
  for (i=0; i<=contacts.length; i++) {

    if (contacts[i].firstName!=firstName){
      answer = "No such contact";
    }
    else if(contacts[i].firstName==firstName && contacts[i].hasOwnProperty(prop)) {
      answer = "No such property";
    }

     else if (contacts[i].firstName==firstName && contacts[i].hasOwnProperty(prop)) {
      answer = firstName +", " + contacts[i].prop; 

    }
    return answer;
but still no go :(
the no such contact property works. but the others dont
ok if i change the second statement to an || expression, that checks out
Sandip Shrestha
@saninmersion
Mar 27 2017 03:59
@ivorygrant your both else if seem identical to me and for some reason I think they should not be
ivorygrant
@ivorygrant
Mar 27 2017 04:00
@saninmersion yes! i changed that
Sandip Shrestha
@saninmersion
Mar 27 2017 04:01
@ivorygrant I used a nested if statement for the second one. using a || operator will mean that it will pass if any of the conditionns are met. But for second property your First condition needs to met and second not met
@ivorygrant also you would like to check if
contacts[i].hasOwnProperty(prop) returns true or false
ivorygrant
@ivorygrant
Mar 27 2017 04:06
@saninmersion ok this is what i updated to:
var answer;
  for (i=0; i<=contacts.length; i++) {

    if (contacts[i].firstName!=firstName){
      answer = "No such contact";
    }
    else if(contacts[i].firstName==firstName && contacts[i].hasOwnProperty(prop)!=prop) {
      answer = "No such property";
    }

     else if (contacts[i].firstName==firstName && contacts[i].hasOwnProperty(prop)) {
      answer = firstName +", " + contacts[i].prop; 

    }
    return answer;

  }
i think i'm close! hmmmm
i tried adding == to the last else if but that didn't work
Sandip Shrestha
@saninmersion
Mar 27 2017 04:08
@ivorygrant why not use a nested if for second and third condition
Joseph
@revisualize
Mar 27 2017 04:09
@ivorygrant Your loop isn't looping.
ivorygrant
@ivorygrant
Mar 27 2017 04:10
argh! ok let me think about this...
Joseph
@revisualize
Mar 27 2017 04:10
@ivorygrant Your previous code was better.
ivorygrant
@ivorygrant
Mar 27 2017 04:10
@revisualize so my solution to declare a variable and return it at the end, is off?
Joseph
@revisualize
Mar 27 2017 04:10
@ivorygrant Look. You don't need everything inside of your for loop.
Bruno Teófilo
@Heirian
Mar 27 2017 04:11
How i can write this line return count + (count > 0 ? " Bet" : " Hold"); without ternary operator?
Joseph
@revisualize
Mar 27 2017 04:11
@ivorygrant You're the only one putting that constraint upon yourself.
@Heirian
if (count > 0) {
    return count + " Bet";
} else {
    return count + " Hold";
}
@ivorygrant This: contacts[i].prop
Dot Notation is converting the value to a string (string literal). Example: myObj.name; is the same as myObj["name"]; and as we all know quotes define strings. If you want to use a variable for accessing the value of object properties you cannot use Dot Notation. You have to use Bracket Notation. Example: var num = 42; myObj[num];
Bruno Teófilo
@Heirian
Mar 27 2017 04:13
ty
ivorygrant
@ivorygrant
Mar 27 2017 04:17
@revisualize when you say "dont neeed everything inside of your for loop" could you give an example?
please :)
Joseph
@revisualize
Mar 27 2017 04:18
@ivorygrant Let me think.

@ivorygrant If I was to do this example where I was looking for a letter in an array of strings.
If the letter is found return the string "True" otherwise return the string "False"

var value = "e"
var arr = ["a", "b", "c", "d", "e"];
for (var i = 0; i < arr.length; i++) {
      if (value === arr[i]) { return "True"; }
}
return "False";

Then if you redid that challenge with the letter "z" as the value of the variable value

Joseph
@revisualize
Mar 27 2017 04:27
@ivorygrant Do you see what I'm trying to get at with my example?
Chris Cullen
@123xylem
Mar 27 2017 04:27
 <div class="container">

        <% if(error&& error.length > 0){
        console.log(error,error.length)%>
            <div class="alert alert-danger" role="alert">
                <%= error %>
            </div>
        <% } %>
        <%  if(success && success.length > 3){ %>
            <div class="alert alert-success" role="alert">
                <%= success %>
            </div>
        <% } %>
    </div>

Why does this function which should look for error or successin flash messages give this response:::

function (req, res, next) { if (req.flash && safe) { return next(); } req.flash = _flash; next(); }

The function seems to just think itself is error and the length is 3 as it has 3 args///
How do i make the function work properly?

ivorygrant
@ivorygrant
Mar 27 2017 04:27
well i followed your first suggestion to update to bracket notation. did that. but as to your example...not seeing it
this is what i have now:
// Only change code below this line
var answer;
  for (i=0; i<=contacts.length; i++) {

    if (contacts[i].firstName!=firstName){
      answer = "No such contact";
    }
    else if(contacts[i].firstName==firstName && contacts[i].hasOwnProperty[prop]!=prop) {
      answer = "No such property";
    }

     else if (contacts[i].firstName==firstName && contacts[i].hasOwnProperty[prop]) {
      answer = firstName +", " + contacts[i][prop]; 

    }
    return answer;

  }
Joseph
@revisualize
Mar 27 2017 04:28
@ivorygrant Your loop still isn't looping.
@ivorygrant You're now not doing .hasOwnProperty() correctly.
ivorygrant
@ivorygrant
Mar 27 2017 04:30
ok, so to reiterate, the .hasOwnProperty() returns a boolean response
Joseph
@revisualize
Mar 27 2017 04:30
@ivorygrant correct.
ivorygrant
@ivorygrant
Mar 27 2017 04:30
"check if this property exists"
ok
Joseph
@revisualize
Mar 27 2017 04:30
@ivorygrant You had .hasOwnProperty() correct before.
ivorygrant
@ivorygrant
Mar 27 2017 04:31
in the parentheses I should pass through prop
Joseph
@revisualize
Mar 27 2017 04:31
@ivorygrant .hasOwnProperty[prop]
Not parenthesis
Those are brackets
@ivorygrant But, still your loop is only running once.
ivorygrant
@ivorygrant
Mar 27 2017 04:33
hmm ok. i'm going to take a walk for a bit. If i'm understanding you correctly i'm making a very basic mistake.
brb!
harryMason
@harryMason
Mar 27 2017 04:36

Hey, would someone like to have a look at my switch statement code?
Instructions: Write a switch statement which tests val and sets answer for the following conditions:
1 - "alpha"
2 - "beta"
3 - "gamma"
4 - "delta"

Here is my code:

function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch(val) {
    case 1:
      console.log("alpha");
      break;
    case 2:
      console.log("beta");
      break;
    case 3:
      console.log("gamma");
      break;
    case 4:
      console.log("delta");
      break;
  }

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

// Change this value to test
caseInSwitch(2);
Joseph
@revisualize
Mar 27 2017 04:36
@harryMason Console.log doesn't change the value of answer ... which at the end you're returning.
harryMason
@harryMason
Mar 27 2017 04:37
@revisualize ahaaa
@revisualize Thanks for the hint :)
CamperBot
@camperbot
Mar 27 2017 04:37
harrymason sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3601 | @revisualize |http://www.freecodecamp.com/revisualize
grantknaver
@grantknaver
Mar 27 2017 04:47
im trying to pass a value and update a the value to true, rather than false.
the value I am trying to effect is activated
here is the code...
```
function block(activated) {
  var checkArray = [
    //row
    ["#cell1", "#cell2", "#cell3"],
    ["#cell4", "#cell5", "cell6"],
    ["#cell7", "#cell8", "#cell9"],

    //column
    ["#cell1", "#cell4", "#cell7"],
    ["#cell2", "#cell5", "#cell8"],
    ["#cell3", "#cell6", "#cell9"],

    //diag
    ["#cell1", "#cell5", "#cell9"],
    ["#cell3", "#cell5", "#cell7"]
  ]
  //alert(checkArray);
  var emptySpot;
  for (var i = 0; i < 7; i++) {
    var prevention = 0;
    $(checkArray[i]).each(function(element,index){
      var target = $(index);
      var targetText = $(index).text();
      if(targetText === ''){
        emptySpot = index;
        alert(emptySpot);
      }
      if(targetText === playerChoice){
        prevention = prevention + 1;
        alert("playerChoice " + index);
        alert("prevention " + prevention);
      } 
    });//each
    if(prevention === 2 && emptySpot != undefined){
       $(emptySpot).html("<p>" + player2Choice + "</p>");
       gridAdjustment(emptySpot); 
       activated = true;
       return emptySpot;//false change maybe
    }
  }//for var i*/
}
```
Edward John
@eddmecha
Mar 27 2017 04:49
var testObj = {
  12: "Namath",
  16: "Montana",
  19: "Unitas"
};

// Only change code below this line;

var playerNumber = 16;       // Change this Line
var player = testObj[16];   // Change this Line
guys what did i wrote wrong?
grantknaver
@grantknaver
Mar 27 2017 04:49
the end goal is to change correction in the ticktac function
I dont want to do a global
screw that
AlanMcDowell888
@AlanMcDowell888
Mar 27 2017 04:49

Using Objects for Lookups -- I'm having trouble with converting the switch statements into a lookup table. This is what I have:

function phoneticLookup(val) {

var result = "";
var lookup = {
"alpha": "Adams",
"bravo":"Boston",
"charlie":"Chicago",
"delta":"Denver",
"echo":"Easy",
"foxtrot":"Frank"

grantknaver
@grantknaver
Mar 27 2017 04:49
am I passing it wrong
AlanMcDowell888
@AlanMcDowell888
Mar 27 2017 04:49
Is that incorrect?
Joseph
@revisualize
Mar 27 2017 04:53
@AlanMcDowell888 Are you modifying result?
grantknaver
@grantknaver
Mar 27 2017 04:53
any ideas
AlanMcDowell888
@AlanMcDowell888
Mar 27 2017 04:54
@grantknaver I'll try to help after I learn
@revisualize that is a good question
Joseph
@revisualize
Mar 27 2017 04:55
@AlanMcDowell888 Great. Can you answer the question?
Travis Bryant
@t-bryant
Mar 27 2017 04:56

I'm having trouble comprehending the stand in line (queue) assignments...this is what I am given: 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));

these are my instructions:
Write a function nextInLine which takes an array (arr) and a number (item) as arguments. Add the number to the end of the array, then remove the first element of array. The nextInLine function should then return the element that was removed.
and the rules:nextInLine([], 1) should return 1
nextInLine([2], 1) should return 2
nextInLine([5,6,7,8,9], 1) should return 5
After nextInLine(testArr, 10), testArr[4] should be 10
Joseph
@revisualize
Mar 27 2017 04:56
@t-bryant You haven't done anything.
harryMason
@harryMason
Mar 27 2017 04:56
@revisualize I did 'answer = "alpha";' instead of 'console.log'. That did the trick. Thanks again for the hint.
CamperBot
@camperbot
Mar 27 2017 04:56
harrymason sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:warning: harrymason already gave revisualize points
Travis Bryant
@t-bryant
Mar 27 2017 04:57
i know i haven't done anything, i don't even know where to start
Joseph
@revisualize
Mar 27 2017 04:57
Write a function nextInLine which takes an array (arr) and a number (item) as arguments. <-- This part has been done for you.
function nextInLine(arr, item) { <--
AlanMcDowell888
@AlanMcDowell888
Mar 27 2017 04:57
@revisualize I am returning "result" which indicates that it is a modifiable variable
Joseph
@revisualize
Mar 27 2017 04:57
@t-bryant Add the number to the end of the array
How do you add the number (item) to the end of the array (arr)?
AlanMcDowell888
@AlanMcDowell888
Mar 27 2017 04:58
var lookup is incorrect, I now see
grantknaver
@grantknaver
Mar 27 2017 04:58
dang @AlanMcDowell888 thanks I just really dont want to do a global var
CamperBot
@camperbot
Mar 27 2017 04:58
grantknaver sends brownie points to @alanmcdowell888 :sparkles: :thumbsup: :sparkles:
:cookie: 206 | @alanmcdowell888 |http://www.freecodecamp.com/alanmcdowell888
Joseph
@revisualize
Mar 27 2017 04:58
@AlanMcDowell888 Umm.. It looked correct to me.
Travis Bryant
@t-bryant
Mar 27 2017 04:59
would i do ([arr}, item)? but using actual numbers?
Joseph
@revisualize
Mar 27 2017 04:59
@t-bryant No.
Makrand R
@makrandr
Mar 27 2017 04:59
Guys how am I supposed to solve the Using Objects for Lookups?
AlanMcDowell888
@AlanMcDowell888
Mar 27 2017 04:59
@grantknaver in python I avoided using global variables by creating callable functions
Makrand R
@makrandr
Mar 27 2017 04:59
challenge
AlanMcDowell888
@AlanMcDowell888
Mar 27 2017 04:59
@grantknaver example: car(keys, wheels)
Travis Bryant
@t-bryant
Mar 27 2017 05:01
i know I am supposed to change something about the line with the return item, i'm just at a loss at to what
ivorygrant
@ivorygrant
Mar 27 2017 05:01
@revisualize ok after some thinking i think my loops runs once because it is not set to a variable?
Joseph
@revisualize
Mar 27 2017 05:01
@ivorygrant No.
ivorygrant
@ivorygrant
Mar 27 2017 05:01
yikes.
Joseph
@revisualize
Mar 27 2017 05:02
@t-bryant Add the number to the end of the array
How do you add the number (item) to the end of the array (arr)?
Travis Bryant
@t-bryant
Mar 27 2017 05:02
arr (2)?
Joseph
@revisualize
Mar 27 2017 05:03
@t-bryant Nope.
AlanMcDowell888
@AlanMcDowell888
Mar 27 2017 05:03

@grantknaver scratch that..
house(kitchen, heat):
heat =

kitchen(heat, floor)'
See how the variable is passed to another function?

Travis Bryant
@t-bryant
Mar 27 2017 05:03
([arr}, 1)?
Joseph
@revisualize
Mar 27 2017 05:03
@t-bryant Nope.
Makrand R
@makrandr
Mar 27 2017 05:04
The instruction reads -Convert the switch statement into a lookup table called lookup. Use it to lookup val and assign the associated string to the result variable... am i supposed to create a - var lookup? How am i supposed to add the val parameter within it?
Manish Giri
@Manish-Giri
Mar 27 2017 05:05
@makrandr the val gets passed in to your function..
you need to create an object called lookup.
Joseph
@revisualize
Mar 27 2017 05:05
@makrandr Have you converted the switch to an object?
grantknaver
@grantknaver
Mar 27 2017 05:05
@AlanMcDowell888 thanks
CamperBot
@camperbot
Mar 27 2017 05:05
grantknaver sends brownie points to @alanmcdowell888 :sparkles: :thumbsup: :sparkles:
:warning: grantknaver already gave alanmcdowell888 points
Makrand R
@makrandr
Mar 27 2017 05:06
I am not sure how the object is gonna look like.. var lookup{ what here? }
AlanMcDowell888
@AlanMcDowell888
Mar 27 2017 05:06
@revisualize any more hints?
Makrand R
@makrandr
Mar 27 2017 05:06
alpha:adams?
Travis Bryant
@t-bryant
Mar 27 2017 05:06
@revisualize , just so we are clear right now, I am so glad you are trying to get me to understand for myself what I need to do and not just giving me the answers...but this is one of those times I wish the answer would just fall into my lap, hahah
Joseph
@revisualize
Mar 27 2017 05:07
@t-bryant
Manipulate Arrays With push()
Manipulate Arrays With pop()
Manipulate Arrays With shift()
Manipulate Arrays With unshift()
grantknaver
@grantknaver
Mar 27 2017 05:08
kinda still confused by that reasoning my argument value should have passed
Doug Carter
@slowtraincar
Mar 27 2017 05:08
Understanding String Immutability

My code: // Setup
var myStr = "Jello World";

// Only change code below this line
myStr= "Hello world";
myStr[0] = "H"; // Fix Me
-what is wrong? thanks!

Joseph
@revisualize
Mar 27 2017 05:09
@slowtraincar You need to remove the line that has myStr[0] = "H"; // Fix Me Because you're supposed to fix that line.
Makrand R
@makrandr
Mar 27 2017 05:09
@slowtraincar myStr[0]="J";
Joseph
@revisualize
Mar 27 2017 05:09
@slowtraincar You ended up leaving that line in so. you didn't actually "fix" it.
Doug Carter
@slowtraincar
Mar 27 2017 05:09
ha! THANK YOU! stuck on this challenge for so long!
Matthew
@IMDBLM
Mar 27 2017 05:13
What's cracking, JS Magicians?
Or, what's good? What are the kids saying nowadays?
ivorygrant
@ivorygrant
Mar 27 2017 05:16
@revisualize i'm going to clear everything and start from scratch. does this initial set up solve the loop issue?
var answer;
  for (i=0; i<=contacts.length; i++){
    for (j=0; j<=contacts[i].length; j++){

      if (contacts[j].firstName==firstName && contacts[j].hasOwnProperty(prop)){

        answer = firstName + ", " + contacts[j].prop;

      }



    }
  }
I think it should as i'm telling it to run through each item in the sub arrays
Joseph
@revisualize
Mar 27 2017 05:20
@ivorygrant Dot Notation is converting the value to a string (string literal). Example: myObj.name; is the same as myObj["name"]; and as we all know quotes define strings. If you want to use a variable for accessing the value of object properties you cannot use Dot Notation. You have to use Bracket Notation. Example: var num = 42; myObj[num];
@ivorygrant That's the first thing I saw.
@ivorygrant Let me look.
Ummm..
AlanMcDowell888
@AlanMcDowell888
Mar 27 2017 05:21

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

// Only change code below this line

result = {
"alpha": "Adams",
"bravo":"Boston",
"charlie":"Chicago",
"delta":"Denver",
"echo":"Easy",
"foxtrot":"Frank"
};

// Only change code above this line
return result[val];
}

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

Joseph
@revisualize
Mar 27 2017 05:21
@ivorygrant Why do you have 2 for loops?
AlanMcDowell888
@AlanMcDowell888
Mar 27 2017 05:21
@revisualize That works, but I didn't follow the instructions
ivorygrant
@ivorygrant
Mar 27 2017 05:21
one for the objects in the contacts, and one for the objects within each contact
Joseph
@revisualize
Mar 27 2017 05:21
@ivorygrant Do Objects have .lengths?
ivorygrant
@ivorygrant
Mar 27 2017 05:22
no only arrays do.
Joseph
@revisualize
Mar 27 2017 05:22
@ivorygrant Oh.
Hmmm
@ivorygrant Why do you have 2 for loops?
ivorygrant
@ivorygrant
Mar 27 2017 05:23
hmmm
guess i'm making this more difficult then it s/b
Joseph
@revisualize
Mar 27 2017 05:24
@ivorygrant You are.
AlanMcDowell888
@AlanMcDowell888
Mar 27 2017 05:25

Got it!
// 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"
};

result = lookup[val];

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

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

thanks @revisualize
CamperBot
@camperbot
Mar 27 2017 05:25
alanmcdowell888 sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3602 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Mar 27 2017 05:26
@AlanMcDowell888 Do you realize when you pasted before you didn't actually paste the whole function?
Travis Bryant
@t-bryant
Mar 27 2017 05:26
@revisualize so on mine...I would jump down below var testArr and go testArr.push("{arr}",item)?
Joseph
@revisualize
Mar 27 2017 05:27
@t-bryant Nope
Travis Bryant
@t-bryant
Mar 27 2017 05:27
at least on the right track?
AlanMcDowell888
@AlanMcDowell888
Mar 27 2017 05:27
Yes.. btw that was a genuine thank you - caused me to think more
@revisualize
Joseph
@revisualize
Mar 27 2017 05:27
@t-bryant Nope.
@t-bryant The only thing correct in that was the .push() but, you didn't .push() correctly.
Travis Bryant
@t-bryant
Mar 27 2017 05:29
so am I going to push the nextInLine?
Joseph
@revisualize
Mar 27 2017 05:29
@t-bryant Look. If I have an array: var myArr = ["a", "e", "i"]; How do you add the value of var vowel = "o"; to then end of myArr?
Brian
@BeardedBry
Mar 27 2017 05:30
hey campers
ivorygrant
@ivorygrant
Mar 27 2017 05:30
@revisualize really appreciate your patience w/ me. if possible i'll go step by step w/ new code attempting to take in your suggestions. so to check if firstName and prop exist:
var answer;
  for (i=0; i<=contacts.length; i++){

    if (contacts[i][firstName]==firstName && contacts[i][prop]==prop){
      answer = firstName +", " + prop;
    }


      }
Travis Bryant
@t-bryant
Mar 27 2017 05:30
myArr.push("o", 3)?
Joseph
@revisualize
Mar 27 2017 05:30
@ivorygrant && contacts[i][prop]==prop this will never be true`
@t-bryant That is incorrect.
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 05:31
hello world
ivorygrant
@ivorygrant
Mar 27 2017 05:31
got it. s/b hasOwnProperty
Joseph
@revisualize
Mar 27 2017 05:31
@ivorygrant This: contacts[i][firstName]==firstNameis also incorrect.
Travis Bryant
@t-bryant
Mar 27 2017 05:32
myArr.push(["o"])?
Makrand R
@makrandr
Mar 27 2017 05:32

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

function checkObj(checkProp) {

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

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

anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 05:32
Joseph
@revisualize
Mar 27 2017 05:32
@makrandr Regarding: myObj.checkProp; .... Dot Notation is converting the value to a string (string literal). Example: myObj.name; is the same as myObj["name"]; and as we all know quotes define strings. If you want to use a variable for accessing the value of object properties you cannot use Dot Notation. You have to use Bracket Notation. Example: var num = 42; myObj[num];
@t-bryant Incorrect.
Makrand R
@makrandr
Mar 27 2017 05:33
ohh @revisualize .. lemme try it out .Thanks
CamperBot
@camperbot
Mar 27 2017 05:33
makrandr sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3603 | @revisualize |http://www.freecodecamp.com/revisualize
ivorygrant
@ivorygrant
Mar 27 2017 05:33
@revisualize i understand why as there is no value associated with firstName, it's just firstName
Joseph
@revisualize
Mar 27 2017 05:34
@ivorygrant What?
ivorygrant
@ivorygrant
Mar 27 2017 05:34
This: contacts[i][firstName]==firstNameis also incorrect.
i'm asking a value of firstName here, but there is no value, right?
Joseph
@revisualize
Mar 27 2017 05:34
@ivorygrant That is incorrect.
ivorygrant
@ivorygrant
Mar 27 2017 05:35
hmm
Travis Bryant
@t-bryant
Mar 27 2017 05:35
myArr.push('o")?
Joseph
@revisualize
Mar 27 2017 05:35
@t-bryant Closer but still incorrect.
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 05:36
@revisualize hi bro
Travis Bryant
@t-bryant
Mar 27 2017 05:36
my bad it was supposed to have double quotes on both sides of the o
"o"
Joseph
@revisualize
Mar 27 2017 05:36
@t-bryant No you're supposed to actually be using the variable vowel
@t-bryant Look. If I have an array: var myArr = ["a", "e", "i"]; How do you add the value of var vowel = "o"; to then end of myArr?
Travis Bryant
@t-bryant
Mar 27 2017 05:36
so vowel.push("o")?
Joseph
@revisualize
Mar 27 2017 05:37
@t-bryant Is vowel an array?
myArr.push(vowel);
Travis Bryant
@t-bryant
Mar 27 2017 05:37
or myArr.vowel("o")?
ok...got it
rrbairar
@rrbairar
Mar 27 2017 05:38
what is the error in this code

var outerWear = "T-Shirt";

function myOutfit() {
// Only change code below this line

var myOutfit= "sweater";

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

myOutfit();

Joseph
@revisualize
Mar 27 2017 05:38
@t-bryant Add the number to the end of the array
How do you add the number (item) to the end of the array (arr)?
Travis Bryant
@t-bryant
Mar 27 2017 05:39
arr.push(item)?
Joseph
@revisualize
Mar 27 2017 05:39
HEY!
And he gets one part of the challenge completed.
Markus Kiili
@Masd925
Mar 27 2017 05:40
@revisualize Good morning.
Travis Bryant
@t-bryant
Mar 27 2017 05:40
lol...with lots of help, thanks
Joseph
@revisualize
Mar 27 2017 05:41
@t-bryant then remove the first element of array.
How do you remove the first element from the array (arr)?
Markus Kiili
@Masd925
Mar 27 2017 05:41
@revisualize I finally ended my being stuck for a year period.
Joseph
@revisualize
Mar 27 2017 05:41
@Masd925 Your what?
Travis Bryant
@t-bryant
Mar 27 2017 05:41
arr.shift(item)?
Markus Kiili
@Masd925
Mar 27 2017 05:41
@revisualize I finally made my first FCC project.
Travis Bryant
@t-bryant
Mar 27 2017 05:41
or is it unshift?
Joseph
@revisualize
Mar 27 2017 05:42
@Masd925 Nice.
@t-bryant .shift() doesn't take an argument
Markus Kiili
@Masd925
Mar 27 2017 05:42
Joseph
@revisualize
Mar 27 2017 05:42
@Masd925 Is this your tribute page?
Markus Kiili
@Masd925
Mar 27 2017 05:43
@revisualize Yes.
Joseph
@revisualize
Mar 27 2017 05:43
@Masd925 OMG.. The bug moving around freaked me out.
Markus Kiili
@Masd925
Mar 27 2017 05:44
@revisualize Good ;)
Joseph
@revisualize
Mar 27 2017 05:45
I seriously tried to squish it with my finger.
Then I realized it wasn't real.
Markus Kiili
@Masd925
Mar 27 2017 05:46
@revisualize You can debug it with the mouse cursor, but they come back...
Chris Cullen
@123xylem
Mar 27 2017 05:47

If i console.log error i get an empty array.

//res.locals:                                // req.flash::
{ currentUser: undefined, error: [], success: [] } '<<err' [Function: _flash]

res.locals.error should make an array that is populated by flash though.. As defined here in my middleware that calls flash>

middlewareObj.isLoggedIn = function(req, res, next){
    if(req.isAuthenticated()){
        return next();
    }
    else{
    req.flash("error", "You need to be logged in to do that");
    res.redirect("/login");}
};

Here is how I set up my app for flash::
res.locals.error=req.flash("error");

anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 05:51
@Lumexralph hi bro
Travis Bryant
@t-bryant
Mar 27 2017 05:52
ok...so if .shift() removes something at the beginning of an array, but .shift( ) doesn't take an argument...then is there another way to remove something at the beginning of an argument...i know .unshift( ) removes and adds at the same time
Travis Bryant
@t-bryant
Mar 27 2017 05:52
or at least from the instructions that what it seemed like
Joseph
@revisualize
Mar 27 2017 05:53
@t-bryant .unshift() doesn't remove anything.
Travis Bryant
@t-bryant
Mar 27 2017 05:53
so it just adds at the beginning instead of at the end like .push( )
Joseph
@revisualize
Mar 27 2017 05:53

Look:
The push() method adds one or more elements to the end of an array and returns the new length of the array.

The pop() method removes the last element from an array and returns that element.

The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.

The shift() method removes the first element from an array and returns that element.

ivorygrant
@ivorygrant
Mar 27 2017 05:53
@revisualize is this any better?
var answer;
var nameLookup=firstName;

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

    if (contacts[i][firstName]==nameLookup && prop.hasOwnProperty(prop)){
      answer = contacts[firstName] +", " + contacts[prop];
    }


      }

    return answer;
Joseph
@revisualize
Mar 27 2017 05:54
@ivorygrant Nope
ivorygrant
@ivorygrant
Mar 27 2017 05:54
hmmm
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 05:54
@ivorygrant hi bro
loudnoyzez
@loudnoyzez
Mar 27 2017 05:54
sorry for such a basic question... can't get the fahrenheit algorithm fahrenheit *= 9/5;
fahrenheit += 32;
ivorygrant
@ivorygrant
Mar 27 2017 05:55
@Anifowose hi!
ivorygrant
@ivorygrant
Mar 27 2017 05:55
sure can help w/ that. what's your question
suhaschauhan
@suhaschauhan
Mar 27 2017 05:56
@loudnoyzez fahrenheit= celsius*(9/5)+32;
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 05:56
@ivorygrant Escaping Literal Quotes in Strings
ivorygrant
@ivorygrant
Mar 27 2017 05:57
@Anifowose yes, what is your question? :)
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 05:58
@ivorygrant i dont no how to do it ; Escaping Literal Quotes in Strings
ivorygrant
@ivorygrant
Mar 27 2017 06:00
@Anifowose what you want to do, is put a backlash before the quotes inside the quotes. so to make a string, you have "" outside the string. then what you want to quote, put a \ before
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 06:00
@ivorygrant k let me try
ivorygrant
@ivorygrant
Mar 27 2017 06:01
you can post your code here so we can see what you're doing
do you know how to do that?
Joseph
@revisualize
Mar 27 2017 06:02
@Anifowose How do you escape a double quote?
loudnoyzez
@loudnoyzez
Mar 27 2017 06:03
@suhaschauhan thanks!
CamperBot
@camperbot
Mar 27 2017 06:03
loudnoyzez sends brownie points to @suhaschauhan :sparkles: :thumbsup: :sparkles:
:warning: @suhaschauhan's account is not linked with freeCodeCamp. Please visit the settings and link your GitHub account.
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 06:04
@ivorygrant no bro
ivorygrant
@ivorygrant
Mar 27 2017 06:05
to post code do this: use ``` then paste your code ctrl+v, then press shift enter
sorry not shift enter. ctrl+enter
@Anifowose is it like that
ivorygrant
@ivorygrant
Mar 27 2017 06:08
you don't paste the link, you paste the actual code
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 06:09
@ivorygrant pls i dont understand the code
ivorygrant
@ivorygrant
Mar 27 2017 06:10
let me clarify: do this ```, then press shift+enter, copy and paste the code, then press ctrl + enter
Joseph
@revisualize
Mar 27 2017 06:10
@Anifowose How do you escape a double quote in a string?
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 06:11
@ivorygrant bro i mean i dont understand the word "code" i dont even no how i can locate it
ivorygrant
@ivorygrant
Mar 27 2017 06:12
when we refer to code it's the main part of the exercise
like this:
var myStr; // Change this line
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 06:13
@ivorygrant k
ivorygrant
@ivorygrant
Mar 27 2017 06:13
@Anifowose when you progress and you get stuck on harder challenges, you will have to share your code so others can help you
otherwise we can't see what you're oding
loudnoyzez
@loudnoyzez
Mar 27 2017 06:14
sharing code like this... var myStr = "He told me he was \"extremely hungry\"."; // Change this line
I think this exercise isn't working right
ivorygrant
@ivorygrant
Mar 27 2017 06:15
var myStr = "He told me he was \"extremely hungry\"."; // Change this line
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 06:15
@ivorygrant ```
var myStr = ""\"I am a "double quoted" string inside "double quotes\"
// Change this line
loudnoyzez
@loudnoyzez
Mar 27 2017 06:15
oh nevermind
haha got it
I thought we were picking our own sentence lol
ivorygrant
@ivorygrant
Mar 27 2017 06:16
np lol
@Anifowose don't delete the ``` at the end of the code
Damaris Muange
@ndush
Mar 27 2017 06:16
Set remainder equal to the remainder of 11 divided by 3 using the remainder (%) operator.
loudnoyzez
@loudnoyzez
Mar 27 2017 06:17
@ndush just set the variable to 11 % 3
thanks @ivorygrant
CamperBot
@camperbot
Mar 27 2017 06:18
loudnoyzez sends brownie points to @ivorygrant :sparkles: :thumbsup: :sparkles:
:cookie: 217 | @ivorygrant |http://www.freecodecamp.com/ivorygrant
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 06:18
@ivorygrant ```var myStr = ""\"I am a "double quoted" string inside "double quotes\"
// Change this line
ivorygrant
@ivorygrant
Mar 27 2017 06:19
@Anifowose it's still not showing properly, the final result should look like this:
var myStr = ""\"I am a "double quoted" string inside "double quotes\"
// Change this line
Joseph
@revisualize
Mar 27 2017 06:19
@Anifowose How do you escape a double quote in a string?
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 06:20
@ivorygrant pls teach me step by step
Joseph
@revisualize
Mar 27 2017 06:20

@ndush What is the returned value of num ... var num = 4 + 3;
What is the returned value of num ... var num = 10 / 5;
What is the returned value of num ... var num = 5 * 3;

Remainder:
http://images.tutorvista.com/cms/images/38/remainder1.PNG
13 % 2 is 1 ... 26 % 5 is 1 ... 24 % 6 is 0
24 % 5 is 4 ... 219 % 20 is 19
Just like in my examples above you use the % operator just like any other math operator (+, -, *, /)

anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 06:20
@Anifowose the 1st thing to do is what?
Joseph
@revisualize
Mar 27 2017 06:20
@Anifowose How do you escape a double quote in a string?
This message was deleted
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 06:21
@revisualize i dont no how to do that i need help on it
ivorygrant
@ivorygrant
Mar 27 2017 06:21
sure. step 1. insert step 2. press shift + enter . step 3. copy and paste the code from the exercise. step 4. press ctrl + enter (do not delete the at the end)
Joseph
@revisualize
Mar 27 2017 06:21
\"
ivorygrant
@ivorygrant
Mar 27 2017 06:21
step 1.```
not sure why it came like that
Joseph
@revisualize
Mar 27 2017 06:22
How do you add a " to that string? Let's say you instantiated the string with double quotes and you want to put in a quote that someone said.
You have to use an escape character. \"
Example: var myQuote = "Happy Feet said, \"I really like the rhythm.\"";
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 06:22
@revisualize k
Joseph
@revisualize
Mar 27 2017 06:24

@Anifowose So, if you have a string:

var myStr = "I am a "double quoted" string inside "double quotes"."; // Change this line

How do you escape the "s inside of the string that you instantiated with double quotes?

Lay
@L-AY
Mar 27 2017 06:24
@forkerino @GarrusNapp Thanks for your help! Instead of using console.log I used return and all test passed in one go! :-)
CamperBot
@camperbot
Mar 27 2017 06:24
l-ay sends brownie points to @forkerino and @garrusnapp :sparkles: :thumbsup: :sparkles:
:cookie: 747 | @garrusnapp |http://www.freecodecamp.com/garrusnapp
:star2: 1725 | @forkerino |http://www.freecodecamp.com/forkerino
Joseph
@revisualize
Mar 27 2017 06:26
@Anifowose You have to escape the double quotes inside of the string by escaping them with the corresponding escape character replacement: \"
ManBearPigg
@ManBearPigg
Mar 27 2017 06:30
how is this cURL command different from this node request http post? To me they look identical but the request post is not working
curl https://svcs.sandbox.paypal.com/AdaptivePayments/Pay \
  -s \
  --insecure \
  -H "X-PAYPAL-SECURITY-USERID: caller_1312486258_biz_api1.gmail.com" \
  -H "X-PAYPAL-SECURITY-PASSWORD: 1312486294" \
  -H "X-PAYPAL-SECURITY-SIGNATURE: AbtI7HV1xB428VygBUcIhARzxch4AL65.T18CTeylixNNxDZUu0iO87e" \
  -H "X-PAYPAL-REQUEST-DATA-FORMAT: JSON" \
  -H "X-PAYPAL-RESPONSE-DATA-FORMAT: JSON" \
  -H "X-PAYPAL-APPLICATION-ID: APP-80W284485P519543T" \
  -d '{
  "actionType":"PAY",
  "currencyCode":"USD",
  "receiverList":{
    "receiver":[
      {
        "amount":"1.00",
        "email":"rec1_1312486368_biz@gmail.com"
      }
    ]
  },
  "returnUrl":"http://www.example.com/success.html",
  "cancelUrl":"http://www.example.com/failure.html",
  "requestEnvelope":{
    "errorLanguage":"en_US",
    "detailLevel":"ReturnAll"
  }
}'



 request.post(
      "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay",
      {
          "headers": {
              "X-PAYPAL-SECURITY-USERID": "caller_1312486258_biz_api1.gmail.com",
              "X-PAYPAL-SECURITY-PASSWORD": "1312486294",
              "X-PAYPAL-SECURITY-SIGNATURE": "AbtI7HV1xB428VygBUcIhARzxch4AL65.T18CTeylixNNxDZUu0iO87e",
              "X-PAYPAL-REQUEST-DATA-FORMAT": "JSON",
              "X-PAYPAL-RESPONSE-DATA-FORMAT": "JSON",
              "X-PAYPAL-APPLICATION-ID": "APP-80W284485P519543T"
          },
          "data": {
              "actionType":"PAY",
              "currencyCode":"USD",
              "receiverList":{
                  "receiver":[
                      {
                          "amount":"1.00",
                          "email":"rec1_1312486368_biz@gmail.com"
                      }
                  ]
              },
              "returnUrl":"http://www.example.com/success.html",
              "cancelUrl":"http://www.example.com/failure.html",
              "requestEnvelope":{
                  "errorLanguage":"en_US",
                  "detailLevel":"ReturnAll"
              }
          }
      },
      function (error, response, body) {
         console.log(body);
      }
  );
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 06:31
@ivorygrant ```
var myStr = ""\"I am a "double quoted" string inside "double quotes\"
// Change this line
Damaris Muange
@ndush
Mar 27 2017 06:31
@revisualize its giving me" Refernce error:invalid assignment left-hand side"
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 06:32
var myStr = ""\"I am a "double quoted" string inside "double quotes\"
// Change this line
ivorygrant
@ivorygrant
Mar 27 2017 06:32
@Anifowose nice, you got it.
@Anifowose so as the challenge says you need to add a backslash before the quotes within the string
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 06:33
@ivorygrant yes sir
loudnoyzez
@loudnoyzez
Mar 27 2017 06:33
btw why is it a carriage return for line 3 here? FirstLine
\SecondLine\
ThirdLine
I don't get why it just isn't another newline like line 2
ivorygrant
@ivorygrant
Mar 27 2017 06:34
since double quoted has quotes around it, where do you think the backslash should go?
I am a "double quoted" string...
where do you think the backslash should go?
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 06:39
back
@revisualize how
ivorygrant
@ivorygrant
Mar 27 2017 06:40
@Anifowose where do you think the backslash in "double quoted" should go?
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 06:42
before n after the code
ivorygrant
@ivorygrant
Mar 27 2017 06:43
@Anifowose so the exercise to add the backslash before the quotes that you want to be double quoted
says*
redoz94
@redoz94
Mar 27 2017 06:44
How do i set a background image for one whole row in bootsstrap? looked everywhere couldnt find a thing
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 06:44
I am a "double quoted" string inside "double quotes".
ivorygrant
@ivorygrant
Mar 27 2017 06:45
@Anifowose right, so where should the backslash go in this example?
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 06:46
\I am a "double quoted" string inside "double quotes\".
ivorygrant
@ivorygrant
Mar 27 2017 06:47
@Anifowose try again
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 06:48
\I am a "double quoted" string inside "double quotes".
Joseph
@revisualize
Mar 27 2017 06:48

@Anifowose Look. If I wanted to make a string for a variable myQuote...
Let's say this was my quote: Happy Feet said, "I really like the rhythm."
I would have to create the variable:

var myQuote;

I would then have to instantiate that variable as a string:

var myQuote = "";

Now I add the string text into the variable.

var myQuote = "Happy Feet said, "I really like the rhythm."";

Then because I have instantiated the string with a double quote. I have to escape the quotes inside of the string.

var myQuote = "Happy Feet said, "I really like the rhythm."";

becomes:

var myQuote = "Happy Feet said, \"I really like the rhythm.\"";

Do you see how that works?
If I did not escape the double quote characters inside of the string text.
JavaScript would think that I am terminating my string.

...
Anyhow. That's all I have time for. Time for me to get to bed.
:v:
ivorygrant
@ivorygrant
Mar 27 2017 06:53
@revisualize thanks for your help! i'm going to give it another crack re: profile lookup
CamperBot
@camperbot
Mar 27 2017 06:53
ivorygrant sends brownie points to @revisualize :sparkles: :thumbsup: :sparkles:
:star2: 3604 | @revisualize |http://www.freecodecamp.com/revisualize
Joseph
@revisualize
Mar 27 2017 06:54
@ivorygrant I'll re-link this: Gist by revisualize / FreeCodeCamp - Profile Lookup.js
Remember: We have an array of objects representing different people in our contacts lists.
Example: var contacts = [ { ... } , { ... } , { ... } , { ... } ];
javascript calc almost done
@revisualize how wasthe conference?
Ezeoke Onyekachi Samuel
@OnyekachiSamuel
Mar 27 2017 07:13
@awb715 Good job man; so much love your design
Jim
@JLOSS1
Mar 27 2017 07:30
hey, could someone take a look at my weather app and tell my why my png isn't working?
http://codepen.io/jloss1/pen/qrKRjV?editors=1111
naimatfz
@naimatfz
Mar 27 2017 07:31

//Setup
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["Javascript", "Gaming", "Foxes"]
}
];

function lookUpProfile(firstName, prop){
// Only change code below this line

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes"); Question : The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.

If both are true, then return the "value" of that property.

If firstName does not correspond to any contacts then return "No such contact"

If prop does not correspond to any valid properties then return "No such property"

anybody? plz
Markus Kiili
@Masd925
Mar 27 2017 07:35
@JLOSS1 You are trying to set the src of an img element?
Syntax should be $("#pic").attr("src", "source here");
Jim
@JLOSS1
Mar 27 2017 07:36
Yeah, I set it as a variable because it changes and then set it as an element for html
ahhhhh man. ok. I gotcha
ManBearPigg
@ManBearPigg
Mar 27 2017 07:37

Why can I access an object inside of this callback but not it's properties?

function callback(error, response, body) {
            if (!error && response.statusCode == 200) {
                console.log(body);
            }
        }

        var result = request(options, callback);

I can log body which is a valid object, but I can't log any of the properties of body. I tried copying the object over to a regular javascript file for testing and I am using the correct notation. The problem has to do with this callback.

Brian
@BrianCodes33
Mar 27 2017 07:37
who wants to code
Jim
@JLOSS1
Mar 27 2017 07:38
@Masd925 changed it to
```
ManBearPigg
@ManBearPigg
Mar 27 2017 07:38

I guess the var result is not necessary nor is the if statement

function callback(error, response, body) {
                console.log(body);
        }

        result(options, callback);

So why can I access the object but not its properties?

Jim
@JLOSS1
Mar 27 2017 07:38
var icon = wd.weather[0].icon;       
      var iconSrc = "http://openweathermap.org/img/w/" + icon + ".png";
      $('#outside').attr(src=iconSrc);
still not working
Markus Kiili
@Masd925
Mar 27 2017 07:39
@JLOSS1 Try $('#outside').attr("src", iconSrc);
Jim
@JLOSS1
Mar 27 2017 07:40
nope.
Markus Kiili
@Masd925
Mar 27 2017 07:42
@JLOSS1 Try logging iconSrc and try if the url works on another tab.
Jor
@joreyesl
Mar 27 2017 07:43
@ManBearPigg what does the it log? and how are you trying to access the properties?
Jim
@JLOSS1
Mar 27 2017 07:44
Hm, doesn't work. I wonder if I have to change the placement of the variable?
ManBearPigg
@ManBearPigg
Mar 27 2017 07:44
@joreyesl It logs an object and I'm accessing the properties using dot notation. When I paste the object into a new js file I can access them just fine. It has something to do with this callback that's preventing me
Jor
@joreyesl
Mar 27 2017 07:45
@ManBearPigg hard to say what is going on without looking at the code
naimatfz
@naimatfz
Mar 27 2017 07:45

@naimatfz

//Setup
var contacts = [
{
"firstName": "Akira",
"lastName": "Laine",
"number": "0543236543",
"likes": ["Pizza", "Coding", "Brownie Points"]
},
{
"firstName": "Harry",
"lastName": "Potter",
"number": "0994372684",
"likes": ["Hogwarts", "Magic", "Hagrid"]
},
{
"firstName": "Sherlock",
"lastName": "Holmes",
"number": "0487345643",
"likes": ["Intriguing Cases", "Violin"]
},
{
"firstName": "Kristian",
"lastName": "Vos",
"number": "unknown",
"likes": ["Javascript", "Gaming", "Foxes"]
}
];

function lookUpProfile(firstName, prop){
// Only change code below this line

// Only change code above this line
}

// Change these values to test your function
lookUpProfile("Akira", "likes"); Question : The function should check if firstName is an actual contact's firstName and the given property (prop) is a property of that contact.

If both are true, then return the "value" of that property.

If firstName does not correspond to any contacts then return "No such contact"

If prop does not correspond to any valid properties then return "No such property"
anybody? plz

Markus Kiili
@Masd925
Mar 27 2017 07:47
@JLOSS1 There might be some async problem too, because you have two ajax calls and you use the first response on the second. You don't really know the order of execution of those callbacks.
Jim
@JLOSS1
Mar 27 2017 07:47
Oh okay. that makes sense.
Markus Kiili
@Masd925
Mar 27 2017 07:48
@JLOSS1 Or is the second call inside the first callback?
Seems to be, so that is not the problem.
Jim
@JLOSS1
Mar 27 2017 07:50
yeah there isn't anything coming up in debug. I thought it would have to be .html and not attribute?
Markus Kiili
@Masd925
Mar 27 2017 07:50
@JLOSS1 The syntax I posted is the correct jQuery way to change image source.
Jim
@JLOSS1
Mar 27 2017 07:51
okay
well, ill continue researching. thanks for the help @Masd925 I must not be doing something right.
CamperBot
@camperbot
Mar 27 2017 07:51
jloss1 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 3660 | @masd925 |http://www.freecodecamp.com/masd925
kirbyedy
@kirbyedy
Mar 27 2017 07:52
@Masd925 what does UUTUUS mean ?
in finish of course :)
ZaCk FroST
@zakwanahmed
Mar 27 2017 07:53
"FirstLine
\SecondLine\
ThirdLine"
i want to get this as out put in jscript
anybody there to help
Markus Kiili
@Masd925
Mar 27 2017 07:54
@kirbyedy It means Novelty.
Jor
@joreyesl
Mar 27 2017 07:55
@JLOSS1 you have that piece of code inside a click function. it only runs when you click the link#toggle. And then you also have that link nested inside a button which makes it impossible to actually click it.
heroiczero
@heroiczero
Mar 27 2017 07:55
@zakwanahmed use the \r and \n and make sure you escape your \
kirbyedy
@kirbyedy
Mar 27 2017 07:57
@Masd925 like new product or something ?
Markus Kiili
@Masd925
Mar 27 2017 07:57
@kirbyedy Yes.
kirbyedy
@kirbyedy
Mar 27 2017 07:58
ok thanks @Masd925
CamperBot
@camperbot
Mar 27 2017 07:58
kirbyedy sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 3661 | @masd925 |http://www.freecodecamp.com/masd925
Jim
@JLOSS1
Mar 27 2017 07:59
@joreyesl If I move the image variable anywhere else, for some reason all of my temperature data disapears
ZaCk FroST
@zakwanahmed
Mar 27 2017 08:00
var myStr='FirstLine \n\ SecondLine\ \rThirdLine'; @heroiczero this is my code but iamnot getting right answerr
ManBearPigg
@ManBearPigg
Mar 27 2017 08:00
@joreyesl The body value returned was actually a string I had to JSON.parse() to get it into an object
Jor
@joreyesl
Mar 27 2017 08:00
@ManBearPigg ah that makes sense.
ManBearPigg
@ManBearPigg
Mar 27 2017 08:00
@joreyesl it got me a downvote on stack overflow but it was worth it lol
heroiczero
@heroiczero
Mar 27 2017 08:00
@zakwanahmed no "space" get rid of the "spaces
ZaCk FroST
@zakwanahmed
Mar 27 2017 08:01
i have tried that too @heroiczero
heroiczero
@heroiczero
Mar 27 2017 08:02
\\n\ you want it to escape the \ not the \n @zakwanahmed
ZaCk FroST
@zakwanahmed
Mar 27 2017 08:02
var myStr="FirstLine\n\SecondLine\\rThirdLine"; @heroiczero
Jor
@joreyesl
Mar 27 2017 08:03

@JLOSS1 i change this

<button id="toggle" class = "button-standard"><a href="#" >C/F</a></button>

and this

$('#outside').attr('src',iconSrc);

and its working for me

ZaCk FroST
@zakwanahmed
Mar 27 2017 08:03
okay it worked thanks @heroiczero
CamperBot
@camperbot
Mar 27 2017 08:03
zakwanahmed sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1048 | @heroiczero |http://www.freecodecamp.com/heroiczero
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 08:13
@ivorygrant hi bro
CC
@Carlos-Cardenas
Mar 27 2017 08:14
<a href="#">
<span class="title">Texto</span>
</a> How to select the span text when you press <a> not using IDs
anifowosebabatunde@yahoo.com
@Anifowose
Mar 27 2017 08:15
@Anifowose @joseph is not too calm
i dont no this things and i appreciate u cos u are patient n calm
n am getting the steps
can we continue from where you stopped pls?
Harry
@HarryTgerman
Mar 27 2017 08:22

var count = 0;

function cc(card) {
// Only change code below this line
if (card = 2,3,4,5,6){
var count = count +1;
} else if (card = 10,"J","Q","K","A"){
var count = count -1;
}else if (count > 0){
return "Bet";
} else if (count < 0) {
return "Hold";
}

return card;

// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(5); cc("K");

i dont understand how i get i summe out of all this values
what im doing wrong ?
heroiczero
@heroiczero
Mar 27 2017 08:23
@HarryTgerman you cant do card = 2,3,4,5,6 that in conditional statement
@HarryTgerman either use a switch or use == and || or signs
@HarryTgerman you should also create a new if/else statement for
}else if (count > 0){
return "Bet";
} else if (count < 0) {
return "Hold";
}
Joy Ajuluchukwu
@joyajulz
Mar 27 2017 08:25
Screen Shot 2017-03-27 at 9.16.17 AM.png @forkerino @Lumexralph here is what I'm doing. This is at 'Word Blanks'. I need help.
heroiczero
@heroiczero
Mar 27 2017 08:27
@joyajulz parameters or variables. you do not need "" around it but you do need " " (spaces) between your words
tech-tron
@tech-tron
Mar 27 2017 08:31
im trying to add an object to an empty array. everytime the condition is met i add the object at the current index of that array to my empty array. when i return this it just says object Object instead of the key:value pair
Harry
@HarryTgerman
Mar 27 2017 08:34

@heroiczero hay thanks for advice !! but somehow i can't display the variable "count" ....
var count = 0;

function cc(card) {
// Only change code below this line
if (card == 2 || card == 3 || card == 4 || card==5 || card == 6){
count = count +1;
}else if (card = 10|| card == "J"|| card=="Q" || card =="K"|| card =="A"){
count = count -1;
}

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

return card,count ;
// Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(5); cc("K");

CamperBot
@camperbot
Mar 27 2017 08:34
harrytgerman sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 1050 | @heroiczero |http://www.freecodecamp.com/heroiczero