These are chat archives for FreeCodeCamp/HelpJavaScript

14th
Nov 2017
Jody LeCompte
@jodylecompte
Nov 14 2017 00:19
Well, that part can be really easy
You just pass whatever color is seleted to the URL,a nd then in that script grab it from the URL
But why load a page without going anywhere?
AbrisM
@AbrisM
Nov 14 2017 00:22
The page is to demonstrate a web-building like application in the new window, is there an example of the URL?
Jody LeCompte
@jodylecompte
Nov 14 2017 00:36
If I understand correctly, it would be totally fine if you were hosting the project outside of codepen
Then you could have two html files, one with your form and button and one that accepts settings and uses them (ie the color of the background), its possible with codepen by creating two pens, but you'd have the codeben bar on the top of both which you might find unsightly
AbrisM
@AbrisM
Nov 14 2017 00:49
Hmm true hahaha
And for this any content displays/changes must be seen in the new window which is basically acting as a user output
That's where it gets tricky because changes/colors must be seen inside when a user clicks "New Window Here"
FlashHero
@FlashHero
Nov 14 2017 00:53
Can someone look at this code and tell me what's wrong, I think I don't understand the variables, but i tried
function permutation(str, n) {
    if (n == 1) {
        return str;
    } else {
        for (var i = 0; i < n; i++) {
            if (n % 2 === 0) {
                var first = str[0]; 
                var second = str[str.length-1];
                 console.log(str.replace(second, first).replace(first, second));
            } else {
                var third = str[i];
                var fourth = str[str.length-1];
                console.log(str.replace(fourth, third).replace(third, fourth));
            }
            return permutation(str, n - 1);
        }
    }
}
permutation('abcde', 5);
Max Voronov
@maxv
Nov 14 2017 02:47
@FlashHero What are you trying to achieve ?
FlashHero
@FlashHero
Nov 14 2017 03:00
@maxv permutation
HandsOmeac
@HandsOmeac
Nov 14 2017 03:42
anybody online ?
Devin Miller
@edwin0258
Nov 14 2017 03:45

@FlashHero

str.replace(second, first).replace(first, second)

This will give you what you started with.

So, I'm guessing that is not the outcome you want.
HandsOmeac
@HandsOmeac
Nov 14 2017 03:47
Someone can help me about FCC challenge of Profile Lookup?
Devin Miller
@edwin0258
Nov 14 2017 03:47
Sure. @HandsOmeac
HandsOmeac
@HandsOmeac
Nov 14 2017 03:48

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 lookUp(firstName, prop)
{
for(var i=0;i<contacts.length;i++)
{
if(contacts[i].firstName==firstName){
if(contacts[i].prop)
{
return contacts[i].prop;
}else return "No such property";

 }else return "No such contact";

}
}

lookUp("Akira", "likes");

what's wrong with this code?
Devin Miller
@edwin0258
Nov 14 2017 03:49
hmm, one sec.
HandsOmeac
@HandsOmeac
Nov 14 2017 03:49
ok
Devin Miller
@edwin0258
Nov 14 2017 03:52
@HandsOmeac
You need to use the bracket notation here because you want to use a variable to access an object property.
if (contacts[i][prop]) {
        return contacts[i][prop];
HandsOmeac
@HandsOmeac
Nov 14 2017 03:53
oh i know
i try
i see
Devin Miller
@edwin0258
Nov 14 2017 04:03
@HandsOmeac You must have also changed the name of the function, so tests couldn't find function. Return should be outside for loop
function lookUpProfile(firstName, prop) {
  for (var i = 0; i < contacts.length; i++) {
    if (contacts[i].firstName == firstName) {
      if (contacts[i][prop]) {
        return contacts[i][prop];
      } else return 'No such property';
    } 
  }
  return 'No such contact';
}
Uriel Guzmán
@Burinson
Nov 14 2017 04:54
[[88, "Bowling Ball"], [2, "Dirty Sock"], [3, "Hair Pin"], [5, "Microphone"],[3, "Half-Eaten Apple"], [7, "Toothpaste"]]
Guys, how can you sort the strings of this array only?
If I apply sort() it will sort the numbers, I don't want that
Ken Haduch
@khaduch
Nov 14 2017 04:58
@Burinson - hello... your sort callback function should select the string element of the array. For example, if you have sort( function(a, b) { a[1] should be compared to b[1] }) and the appropriate return made for a string comparison. (Sort of pseudocode-ish...) If I got your intent correct, that is...
HandsOmeac
@HandsOmeac
Nov 14 2017 05:02
@edwin0258 ok thx
already changed
Uriel Guzmán
@Burinson
Nov 14 2017 05:26
@khaduch Yeah, that's my intent
arr1 = arr1.sort(function(a, b) { return a[1], b[1]; });
What am I doing wrong?
NVM, I googled how to sort strings
arr1 = arr1.sort(function(a, b) {
      if (a[1] < b[1]) {
    return -1;
  }
  if (a[1] > b[1]) {
    return 1;
  }

  // names must be equal
  return 0;

  });
Uriel Guzmán
@Burinson
Nov 14 2017 05:31
@khaduch thanks
korzo
@korzo
Nov 14 2017 06:29
Mastering React book today for free https://www.packtpub.com/packt/offers/free-learning
Long Nguyen
@longnt80
Nov 14 2017 07:12
@korzo thanks :+1:
Ashwin
@ashwins93
Nov 14 2017 07:13
@korzo Thanks a lot seems really useful
Marius Nicolae
@bytao7mao
Nov 14 2017 08:18
Hello guys, can someone help me to filter an api?
Claudio Restifo
@Marmiz
Nov 14 2017 08:23
@bytao7mao wdym?
Marius Nicolae
@bytao7mao
Nov 14 2017 08:43
i'll send the codepen
this works
Claudio Restifo
@Marmiz
Nov 14 2017 08:48
The API sends you an array of object, what exactly do you mean by "filter"?
I presume you want to apply some markup with the data you receive, is that what you mean?
Claudio Restifo
@Marmiz
Nov 14 2017 08:57
@bytao7mao
Marius Nicolae
@bytao7mao
Nov 14 2017 09:03
i have another api, but i want to filter it
1.the api it doesn't work
2.i want to filter by country
i'll send the api link private
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 10:06
hello everyone
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 10:32
anyone around»
abraham anak agung
@padunk
Nov 14 2017 10:32
yeah, just staring at this empty room :smile:
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 10:42
function firstDuplicate(a) {
    let dup = [];
    for (let i = 0; i < a.length; i++) {
        let temp = a.slice(i + 1);
        if (dup[0] && dup[0] < i) {
            break;
        }
        for (let j = 0; j < temp.length; j++) {
            let sum = i + j + 1;
            if (dup.length === 0 || dup[0] > sum) {
                if (a[i] === temp[j]) {
                    dup[0] = sum;
                    dup[1] = a[i];
                }
            } else {
                break;
            }
        }
    }
    return dup.length > 0 ? dup[1] : -1;
}
strange way of dealing it thimngs but ended up with this started with something quite simple but it timesout in 2 big tests
anyway to avoid this that I might be forgettign or other work around?
Marius Nicolae
@bytao7mao
Nov 14 2017 10:48
@Marmiz thanks man!
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 10:48
well one of tests has a 5k array no hard to understand why timesout :p
Blauelf
@Blauelf
Nov 14 2017 10:57
@tiagocorreiaalmeida Nested loops are most likely not O(n)\mathcal{O}(n). You are meant to find the first second occurrence. I did some early return pattern:
function firstDuplicate(a) {
  let dup = [];
  for (let n of a)
    if (dup[n])
      return n;
    else
      dup[n] = true;
  return -1;
}
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 10:59
I might be confused but you still have to handle if there's a value that's the first number in the arrayt and the last that's the first occurrence but right after arr[1] and arr[2] are equal and those indexes are smaller and as far as I got it you have to return the smaller occurence based on the index?
or maybe complicated it
Blauelf
@Blauelf
Nov 14 2017 11:07

You have to return the number that has its earliest second occurrence. So I just remembered any element seen so far, and on the first duplicate would return that one.

Just that it's O(n)\mathcal{O}(n) in both memory and time, while for memory O(1)\mathcal{O}(1) was requested.

But works.
Stephen James
@sjames1958gm
Nov 14 2017 11:22
@tiagocorreiaalmeida I don't like that you have to modify the input array - but here is one that passes:
function firstDuplicate(a) {
    for (var i =0; i < a.length; i++) {
        let reali = a[i] > a.length ? a[i] - a.length - 1 : a[i] - 1;
        if (a[reali] > a.length) return reali + 1;
        a[reali] += a.length;
        // console.log(a);
    }
    return -1;
}
Using the input array as your storage then you don't have to use any other memory
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 11:31
still trying to figure out how you pulled that out of your head :D
Stephen James
@sjames1958gm
Nov 14 2017 11:37
Since the numbers are limited to <= a.length I could add a.length to each as an indicator that the number had been seen
abraham anak agung
@padunk
Nov 14 2017 11:38
@sjames1958gm what is let reali do? i still confuse with the code
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 11:39
assisngs a value based on a if
if the value of a[i] is greater than a.length the value of reali will be a[i] - a.length - 1
otherwise a[i] - 1;
those are called ternary operators
abraham anak agung
@padunk
Nov 14 2017 11:40
@tiagocorreiaalmeida yes i know that one, i mean what that variable for?
Stephen James
@sjames1958gm
Nov 14 2017 11:40
@padunk I am using the values in the array as indexes back into the array. So that code
makes sure the value is 0 to a.length -1
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 11:42
in thsi case you avoid check the same value multiple times right?
Stephen James
@sjames1958gm
Nov 14 2017 11:42
yes, the first time I encounter a value that has already been modified - done
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 11:43
still a bit confused tbh I wouldnt come with something like that I guess I have to pratice more algorithms
abraham anak agung
@padunk
Nov 14 2017 11:45
yeah, i still confused how @sjames1958gm come with that but after read it again, the number are limited to <= a.length so, i think i get it. Thank you, this is a great lesson to learn
Stephen James
@sjames1958gm
Nov 14 2017 11:45
The bad thing is that you are mutating the input :(
abraham anak agung
@padunk
Nov 14 2017 11:48
yes, it is
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 12:01
yeah the second question compared to this one
is nothing
by the way has anyone taken this thing from codefights from start to end on the pratice part?
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 12:23
btw @Blauelf where can I read about O(n) ? and what does effect it
still not quite sure how it works I know it related to memory storage but
nandoBel
@nandoBel
Nov 14 2017 12:29
Hi! Task is to make a program that writes the sum of two number. Would you say this covers it: const number1 = 2;
const number2 = 5;
console.log(number1+number2);
Blauelf
@Blauelf
Nov 14 2017 12:31
@tiagocorreiaalmeida I think I once saw a series of videos on big-O, not sure where that was. These videos also showed how matrix multiplication can be brought down from O(n3)\mathcal{O}(n^3) to O(nlog27)\mathcal{O}(n^{\log_2{7}}). There are also other metrics that are related.
nandoBel
@nandoBel
Nov 14 2017 12:31
Would this be considered a program or not?
Aizaz Shahid
@aizazshahid
Nov 14 2017 12:33

@nandoBel

A computer program is a collection of instructions that performs a specific task

So by that, yes !

nandoBel
@nandoBel
Nov 14 2017 12:34
Ok, thanks
Blauelf
@Blauelf
Nov 14 2017 12:34
@nandoBel It's a list of instructions, and with node.js, you could run this as a programme. Most programmes are a bit more complex, with functions and stuff.
Aizaz Shahid
@aizazshahid
Nov 14 2017 12:34
@cmccormack are you there ?
nandoBel
@nandoBel
Nov 14 2017 12:34
Cause I guess this would be a better solution to the same task

let number1 = 2;
let number2 = 3;
let sum = number1 + number2;

console.log(The sum of ${number1} and ${number2} = ${sum});

Aizaz Shahid
@aizazshahid
Nov 14 2017 12:36
@nandoBel you are right but we have to solve problems in the order which FCC wants : )
Markus Kiili
@Masd925
Nov 14 2017 12:36
@tiagocorreiaalmeida Coursera has a Princeton algorithm course that covers algorithm complexity.
Aizaz Shahid
@aizazshahid
Nov 14 2017 12:37
@Masd925 How are you ? forwebtech here !
Blauelf
@Blauelf
Nov 14 2017 12:37
@sjames1958gm Oh, this solution is interesting.
@Masd925 I think that might be the one I've watched.
Markus Kiili
@Masd925
Nov 14 2017 12:38
@aizazshahid Fine. Starting to do my portfolio page (finally).
nandoBel
@nandoBel
Nov 14 2017 12:38
@aizazshahid Meaning both solutions are equally good?
Aizaz Shahid
@aizazshahid
Nov 14 2017 12:39
@Masd925 at last : )
@nandoBel it depends, can you tell me why we create variables ?
Michael
@gitChimp88
Nov 14 2017 12:39
Hello everybody, im stuck on an algorithm, Sum all odd fibonacci numbers, im trying to figure out a way to push all fibonacci numbers to an array which i could then loop through and use a conditional to sum all of the odd ones, but how to actually push the numbers is boggling me...
nandoBel
@nandoBel
Nov 14 2017 12:40
@aizazshahid To store data?
Aizaz Shahid
@aizazshahid
Nov 14 2017 12:41
@nandoBel indeed, precisely, when we need to use that data more than once !

@nandoBel
here:

let number1 = 2;
let number2 = 3;
let sum = number1 + number2;

if need that sum more than once than it is a good idea to use it, otherwise it doesn't necessary.

nandoBel
@nandoBel
Nov 14 2017 12:42
I see
@aizazshahid Thanks!
Aizaz Shahid
@aizazshahid
Nov 14 2017 12:43
:+1: @nandoBel
Blauelf
@Blauelf
Nov 14 2017 12:45

@gitChimp88 Most importantly: You need the sum of all odd fibonacci numbers less than or equal num, not the first num fibonacci numbers. That's a common misconception.

You can start with two variables, one at 0, second at 1, in a loop push one of them (doesn't matter with those starting values), then replace the first with the second and the second with the sum of both, just at once. You might want to use some maths tricks, ES6 array deconstruction, or a helper variable. Repeat that as long as the variable to push is not larger than num.

Michael
@gitChimp88
Nov 14 2017 12:47
@Blauelf thanks ill try this method out
Aizaz Shahid
@aizazshahid
Nov 14 2017 12:48
Bot
@Bot are you sleeping : )
Blauelf
@Blauelf
Nov 14 2017 12:50
cbot status
CamperBot
@camperbot
Nov 14 2017 12:50
All bot systems are go!
botVersion: 0.0.12
env: prod
botname: camperbot
Aizaz Shahid
@aizazshahid
Nov 14 2017 12:51
@Blauelf brownies system is removed ?
Blauelf
@Blauelf
Nov 14 2017 12:51
Why should it?
about @aizazshahid
Aizaz Shahid
@aizazshahid
Nov 14 2017 12:52
its not showing to me ?
Blauelf
@Blauelf
Nov 14 2017 12:52
Hmm...
about @blauelf
Aizaz Shahid
@aizazshahid
Nov 14 2017 12:52
about @Blauelf
Blauelf
@Blauelf
Nov 14 2017 12:52
Not running it seems :/
Aizaz Shahid
@aizazshahid
Nov 14 2017 12:53
seems, its offline.
Blauelf
@Blauelf
Nov 14 2017 12:53
Last cookie yesterday (in my time zone, which is GMT+1) :point_up: 13. November 2017 21:19
Jake
@JakeDVirus
Nov 14 2017 13:43
is there anything wrong in this statement $headerComponent.delay(300).removeClass("unscrolled");??
The delay method is not executing and the class unscrolled is getting removed instantly.
The given statement is from below snippet
    var $headerComponent = $(".header-wrapper");
    $(window).on("scroll", function(){
        var displacementFromTop = window.pageYOffset || document.documentElement.scrollTop;
        if (displacementFromTop > 0) {
            $headerComponent.delay(300).removeClass("unscrolled");
        } else {
            $headerComponent.addClass("unscrolled");
        } 
    });
Ronique Ricketts
@RoniqueRicketts
Nov 14 2017 13:45
@NeelDVirus .delay(300) is 300ms not seconds just so you know.
thats pretty fast
Jake
@JakeDVirus
Nov 14 2017 13:45
@RoniqueRicketts yeah i know i needed 0.3sec
just a sec
actually the transition affect is of 0.3sec. so you understand why 0.3sec @RoniqueRicketts
and the transition affect of 0.3sec is not seen which was associated with the class unscrolled
even i make it 3000 from 300 (just to cross check), no affect
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 13:55
@NeelDVirus may I ask what's the context and the idea of the code above?just for curiosioty
Stephen James
@sjames1958gm
Nov 14 2017 13:58
@NeelDVirus I believe that delay only delays certain jquery "effects" functions of which removeClass is not
Jake
@JakeDVirus
Nov 14 2017 14:02
@tiagocorreiaalmeida It's bit complicated to explain. this is for the header inside which the nav-bar also resides. and this specific context(snippet) is for mobile version (with humburger icon). Initially the header will be bigger in size, when the user will scroll down the page the, the header(including the logo and hamburger-icon will shrink down with the transition of 0.3sec) but the problem is hamburger icon also have its transition of clicked-version which get kinda mixed. so i overridded the transition of humburger icon (only which are getting affected by the transition of header when scrolled) in an extra class ".unscolled". hope i made sense in explaining
@sjames1958gm i figured out in the documentation that .delay() is for limited stuff (something like that). what is need is the native javascript's WindowOrWorkerGlobalScope.setTimeout(). going to try that out
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 14:03
like a nav with 90px to 60px?
Stephen James
@sjames1958gm
Nov 14 2017 14:04
@NeelDVirus yes
Jake
@JakeDVirus
Nov 14 2017 14:06
@tiagocorreiaalmeida yeah. just have to change the font-size of HEADER from 2rem to 1.6rem and since the hamburger-icon-component's and logo-component's main font-size and everything is set in em so everything will be shrink on its own
@sjames1958gm thanks
Stephen James
@sjames1958gm
Nov 14 2017 14:06
@NeelDVirus :+1:
Ronique Ricketts
@RoniqueRicketts
Nov 14 2017 14:08
@sjames1958gm hey man.
whats up?
Stephen James
@sjames1958gm
Nov 14 2017 14:08
@RoniqueRicketts Not much, reading about blockchain.
Ronique Ricketts
@RoniqueRicketts
Nov 14 2017 14:09
@sjames1958gm You know that is my December read. :) nice. Are you good with WP?
Stephen James
@sjames1958gm
Nov 14 2017 14:09
@RoniqueRicketts No
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 14:10
couldnt that be made with css on the unscrolled class with some transition?
and just add and remove the class?
anyway Idont know the real situation, so happy you got it working :D
Ronique Ricketts
@RoniqueRicketts
Nov 14 2017 14:11
@sjames1958gm face-slap. how could you. I have a project that I want to edit. My php skills are really low atm I wash I could convert wp to javascript and debug it
Stephen James
@sjames1958gm
Nov 14 2017 14:12
@RoniqueRicketts lol - my php skills are also quite low.
Ronique Ricketts
@RoniqueRicketts
Nov 14 2017 14:12
@sjames1958gm lol I just know the basic PhP. I am all wrapped up with Javascript. :)
Jake
@JakeDVirus
Nov 14 2017 14:13
@tiagocorreiaalmeida yeah i did that. but as the unscrolled class wil be removed as the user will scroll so the overrided css of trasition wont work.
i am sending you the link to github. if you think you have time then check that out and see if you can do it without any JS, may be i am missing something
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 14:22
you can convert wp php files to js? well that's something I havent heard but sounds interesting
Nazar
@IsaakNazar
Nov 14 2017 14:29
im struggling , cant remove previous results when hit search button or enter key
https://codepen.io/NazarIsaak/pen/rYwEjg
Stephen James
@sjames1958gm
Nov 14 2017 14:34
@IsaakNazar after you call wikiLoad()
e.target.value = ""
@IsaakNazar Right before your for loop clear the current innerHTML div1.innerHTML="";
Nazar
@IsaakNazar
Nov 14 2017 14:37
@sjames1958gm yess Stephen thanx :)
Kevin Peña
@kebien6020
Nov 14 2017 14:44
setTimeout(() => $headerComponent.removeClass('unscrolled'), 300)
@NeelDVirus this is probably what you want to use
eswhy27
@eswhy27
Nov 14 2017 15:50

Hello I am working on the "title case a sentence" bonfire, where you are supposed to capitalize the first letter of each word in a sentence

link: https://www.freecodecamp.org/challenges/title-case-a-sentence

In my code I am wondering why my for loop is not iterating through each string in my "splitter" variable, it is only returning the first word.

function titleCase(str) {
  var splitter = str.toLowerCase().split(" ");
  for (i=0; i<splitter.length; i++){
    var ans = splitter[i].replace(splitter[i].charAt(0),  
    splitter[i].charAt(0).toUpperCase()); 
    return ans;
  } 

}

titleCase("I'm a little tea pot");
Kaz Baig
@kbaig
Nov 14 2017 15:56
@eswhy27 because you have a return statement in your loop, so the function will return during the first iteration
Christopher McCormack
@cmccormack
Nov 14 2017 15:57
@eswhy27 return completely breaks out of the function in which it is scoped, you need to move that outside your loop
eswhy27
@eswhy27
Nov 14 2017 15:59
@kbaig @cmccormack thanks, I was thinking that was the problem... I'm assuming it would be smarter to not declare the "ans" variable then?
Christopher McCormack
@cmccormack
Nov 14 2017 15:59
@eswhy27 you should really try to avoid declaring variables inside a loop
Kaz Baig
@kbaig
Nov 14 2017 16:00
Why not
unless it's async
Christopher McCormack
@cmccormack
Nov 14 2017 16:00
Something to do with overhead, don't recall the exact reason
Kaz Baig
@kbaig
Nov 14 2017 16:00
wait no im not thinking of for loops
nvm
eswhy27
@eswhy27
Nov 14 2017 16:02
okay so my code now looks like this and if I return my orignal splitter variable it just returns var splitter = str.toLowerCase().split(" "); ignoring all of what I have written in my for loop....is that becasue strings are immutable?
function titleCase(str) {
  var splitter = str.toLowerCase().split(" ");
  for (i=0; i<splitter.length; i++){
    splitter[i].replace(splitter[i].charAt(0),  
    splitter[i].charAt(0).toUpperCase()); 
  } 
}
how do i return what is inside my loop?
Christopher McCormack
@cmccormack
Nov 14 2017 16:02
splitter is an array when you use the split method
array members are mutable so you can take the result of your replace method and store it in the array in that position
Kaz Baig
@kbaig
Nov 14 2017 16:03
@eswhy27 you could look at the array map method as an alternative to using a for loop here
Christopher McCormack
@cmccormack
Nov 14 2017 16:03
sorry, let me be clear, array members can be changed, as arrays are just indexes with pointers to something
eswhy27
@eswhy27
Nov 14 2017 16:03
right gotcha, okay let me take a stab at it real quick.
@cmccormack @kbaig thank you!
but yeah im assuming ill be back to ask more questions...lol
Christopher McCormack
@cmccormack
Nov 14 2017 16:05
@eswhy27 here is a quick example - logging your values can help immensely, and using a REPL lets you 'whiteboard' it easily:
> var str = 'this is a test'
> var arr = str.split(' ')
> arr
[ 'this', 'is', 'a', 'test' ]
> arr[2] = 'not a'
'not a'
> arr
[ 'this', 'is', 'not a', 'test' ]
> arr.join(' ')
'this is not a test'
Jason Luboff
@JLuboff
Nov 14 2017 16:06
Morning
Christopher McCormack
@cmccormack
Nov 14 2017 16:06
@JLuboff yo!
I got a question for you or anyone else that's worked on Node a bit
Jason Luboff
@JLuboff
Nov 14 2017 16:06
Sure
Christopher McCormack
@cmccormack
Nov 14 2017 16:07
I'm trying to setup a 404 error or a redirect when a user goes to a path that doesn't exist
so this is what I put in place
Jason Luboff
@JLuboff
Nov 14 2017 16:08
oook
Christopher McCormack
@cmccormack
Nov 14 2017 16:08
one sec sorry haha
Jason Luboff
@JLuboff
Nov 14 2017 16:08
lol
Christopher McCormack
@cmccormack
Nov 14 2017 16:08
const root = path.resolve(__dirname, '..')
const static = path.join(root, 'static')
...
  app.get('*', (req, res) => {
    console.log(`New Request for ${req.hostname + req.path}`)
    res.sendFile(path.join(static, 'index.html'))
  })
So... this works ok until I start adding additional paths like /path1/path2
Jason Luboff
@JLuboff
Nov 14 2017 16:09
Do you add /path1/path2 above or below that route?
Christopher McCormack
@cmccormack
Nov 14 2017 16:09
then it loads the index but all my relative links will be broken
Jason Luboff
@JLuboff
Nov 14 2017 16:09
You want that route to be last
alpox
@alpox
Nov 14 2017 16:10
@cmccormack if you add them below, they get ignored. If you put them above, they are not.
Christopher McCormack
@cmccormack
Nov 14 2017 16:10
sorry quick add - I'm using React with React Router v4 as well
so loading /login will be routed using react router, but /login/blah should load the main component using * within react router
so i'm only using Node as my API for login currently, (post to /login) but all other requests should load my index.html
alpox
@alpox
Nov 14 2017 16:13
@cmccormack add the specific routes before the one with *to express
Christopher McCormack
@cmccormack
Nov 14 2017 16:14
I guess my question is - is there a good way in node to maybe redirect /path1/path2/.../pathN to / but have other paths like /login resolve the way it is above using sendFile
@alpox yeah... I did try adding the specific paths and just doing nothing with them (React Router should handle them) and using * to redirect, it worked but wasn't sure if it was the proper way, and would require me modifying an array every time I add a new path
Jason Luboff
@JLuboff
Nov 14 2017 16:20
@cmccormack I'm not familar with how react and react router work with node and its routing
Christopher McCormack
@cmccormack
Nov 14 2017 16:21
@JLuboff I'm not sure if react router is too important to the question - I really just need it to redirect if it matches a pattern like /path1/path2/.../pathN but sendfile for anything else I guess
I only mention it because react router will be handling all my paths I do want after node presents my react app index.html
hmm would something like app.get('/:path1/*') work maybe?
Jason Luboff
@JLuboff
Nov 14 2017 16:25
try it?
Christopher McCormack
@cmccormack
Nov 14 2017 16:27
@JLuboff maybe I will :p
@JLuboff @alpox thanks
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 16:28
@cmccormack voting app?
Christopher McCormack
@cmccormack
Nov 14 2017 16:28
@tiagocorreiaalmeida yes
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 16:29
uh nice
Jason Luboff
@JLuboff
Nov 14 2017 16:30
WHERE ARE MY BROWNIES?!
:P
Christopher McCormack
@cmccormack
Nov 14 2017 16:31
@JLuboff brownie store
why isn't a singular brownie a browny?
Kaz Baig
@kbaig
Nov 14 2017 16:32
brownies seem to be RIP today
Jason Luboff
@JLuboff
Nov 14 2017 16:32
@cmccormack Becuase then they'd be a paper towel...
Christopher McCormack
@cmccormack
Nov 14 2017 16:32
haha
Christopher McCormack
@cmccormack
Nov 14 2017 16:39

this seems to work:

  app.get('/:path/*', (req, res) => {
    console.log(`New Request for ${req.hostname + req.path}`)
    res.redirect('/')
  })

and React router will handle the invalid paths at the root level - thanks again @JLuboff and @alpox - enjoy your calorie free browny!

Jason Luboff
@JLuboff
Nov 14 2017 16:43
:+1:
"My computer is running super slow, can you take a look at it?" Opens task manager... CPU maxed at 100% "...why don't we try restarting"
And on that note, I'm out for a bit!
Christopher McCormack
@cmccormack
Nov 14 2017 16:49
@JLuboff later browny
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 16:52
well at least they ask you gently :D
Ken Haduch
@khaduch
Nov 14 2017 16:53

@Burinson re: :point_up: November 14, 2017 12:26 AM - you need to write your sort function to compare the strings. The MDN Array.sort documentation has a lot of detail. You want to do something like this:

arr1 = arr1.sort( function(a, b) {
    if ( a[1] > b[1] ) {
        return 1;
    }
    if ( a[1] < b[1] ) {
        return -1;
    }
    return 0;
}

There might be a more clever way to write it, but that's the general idea - compare the strings and return the value to reflect the comparison results. The example on the documentation page also shows converting the strings to uppercase for a case-insensitive comparison. It all depends on your requirements.

@Burinson - OOPS - I just read the post you made and saw that you figured it out... :)
Kristina
@kikidesignnet
Nov 14 2017 18:03
Anyone free for another private chat with me for help? I'm getting closer to solving the problem that I've been working on for the last few days but I still need help with my JS Calculator......
Hello?
Kaz Baig
@kbaig
Nov 14 2017 18:06
Why not just post your question here
More eyeballs
Kristina
@kikidesignnet
Nov 14 2017 18:07
I could but all the people typing here for different conversations is really confusing and interruptive....
Kaz Baig
@kbaig
Nov 14 2017 18:07
I mean
last message was over an hour ago
Kristina
@kikidesignnet
Nov 14 2017 18:09
I see. then I'll post the question here. I have my original code which works mostly. It's https://codepen.io/kikibres/pen/MEQvqv. The only problem is that if I press "5" and then "+", but changed my mind and pressed "-", the history areay should display "5-" instead of "5+".
I was able to fix it with my forked codepen: https://codepen.io/kikibres/pen/RjgJbz?editors=0010. But when I entered multiply operations like this: "1+2+3=", the history area doesn't work properly...
All the actions happens in function addOperator(keyitem)
Kaz Baig
@kbaig
Nov 14 2017 18:12
There must be a mismatch between where you are storing operations and where you are displaying them
Kristina
@kikidesignnet
Nov 14 2017 18:13
Did you see my forked codepen?
Kaz Baig
@kbaig
Nov 14 2017 18:13
Yep
Stephen James
@sjames1958gm
Nov 14 2017 18:13
@kikidesignnet You'll have to have some 'state' that says change history vs. use operator as operator.
Kaz Baig
@kbaig
Nov 14 2017 18:13
^ that
Another issue I noticed is pressing the equals button more than once in a row results in strange behavior
Stephen James
@sjames1958gm
Nov 14 2017 18:14
@kikidesignnet Hmm it seems to work the first time but not again
Kaz Baig
@kbaig
Nov 14 2017 18:15
And trying to enter a decimal as the first operation doesn't seem to work either...Are you setting a default value or is it just undefined?
Kristina
@kikidesignnet
Nov 14 2017 18:15
please don't create any more problems for me to fix too in equal button T_T
I'm trying to go step by step to fix each problem and the problem I'm fixing right now is additonal operators...
I've been working on this problem the past few days T_T
Kaz Baig
@kbaig
Nov 14 2017 18:18
You'll get there!
I faced the same issues when I was doing this challenge
Kristina
@kikidesignnet
Nov 14 2017 18:19
At this point I want someone to write the solution so that I can see what's wrong with my code...
so far my forked codepen did fix the problem but created more bugs!!
Kaz Baig
@kbaig
Nov 14 2017 18:21
Once you figure out how to fix all the problems, you'll be able to do a quick clean rewrite
Struggling is how you learn
Kristina
@kikidesignnet
Nov 14 2017 18:23
I could if someone show me the solution to that problem! Sometimes in some case solutions helps by pointing out what I could have overlooked or never thought of before...
Do you have the solution?
Kaz Baig
@kbaig
Nov 14 2017 18:25
Too much going on in the code for me to have time to look at it at the moment, I'm afraid. Maybe someone else is available?
Kristina
@kikidesignnet
Nov 14 2017 18:25
Yeah that would be helpful
Also please take your time to take a look at the codepen. I can wait since I have several other things to do as well.
Meanwhile, I will post this problem on freecodecamp forum too..
Ronique Ricketts
@RoniqueRicketts
Nov 14 2017 18:45

Hello guys I have a little canvas issue

<canvas id="myCanvas" width="500" height="500" style="border:1px solid #000000;">

</canvas>
script

var canvas = document.getElementById('myCanvas');
var img = new Image();
var fullImage = img.src="https://vignette.wikia.nocookie.net/phineasandferb/images/6/6a/Doofenshmirtz_official.jpg/revision/latest?cb=20140503030926";
img.addEventListener("load", function(e){
console.log(img.src);
}, false);
drawImage(fullImage, 50, 50);

why wont this render?

fixed my error
Jason Luboff
@JLuboff
Nov 14 2017 18:47
It's been a while since I've worked with canvas...but..don't you have to specify the canvas to draw to?
Ronique Ricketts
@RoniqueRicketts
Nov 14 2017 18:47
I didn't set the canvas to 2d
Jason Luboff
@JLuboff
Nov 14 2017 18:47
..or that
Ronique Ricketts
@RoniqueRicketts
Nov 14 2017 18:49
can a regular canvas like this be draggable?
Jason Luboff
@JLuboff
Nov 14 2017 18:49
Not sure
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 18:50
@JLuboff in a case of mongodb db of many users to one book and many books to one user how would you behave?as a normally in sql? a table with 2 foreign keys?
Jason Luboff
@JLuboff
Nov 14 2017 18:52
@tiagocorreiaalmeida Ehhh...since mongo is NoSQL it doesn't really follow the same rules of normalization. I did use two collections, one for users, one for games. And then I stored the users (that is, I have an array owner and have an object containing user, platform, username, actualUsername (due to my user structure)) in an array within the game document. Probably not the best method, but to do what you're describing requires using something like $lookup in an aggregate, otherwise, you can't get data from two different collections at once
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 18:54
yeah guess im following that method aswell my first tough was having the book directly in the user collection but well that would create somekind of issue in a real world situation with the ammount of duplicated data
Jason Luboff
@JLuboff
Nov 14 2017 18:54
Ya, I reduced duplicate data by only having one document containing the game and using a sub-document (aka, an array within the document) to hold the user info
Tiago Correia
@tiagocorreiaalmeida
Nov 14 2017 18:56
in this case I think hold only the user id is what it takes if you can make some kind of relation between them well nothing I cna't learn lets see
Jason Luboff
@JLuboff
Nov 14 2017 18:59
@tiagocorreiaalmeida Ya you'd have to use $lookup to get any info from that
Lean Junio
@leanjunio
Nov 14 2017 18:59
hey guys, how can I send my response (res) to the scope of app.get?
app.get('/', (req, res) => {
  axios.get('https://developers.zomato.com/api/v2.1/categories', config)
  .then((res) => console.log(res))
  .catch(error => console.log(error))
})
Jason Luboff
@JLuboff
Nov 14 2017 19:00
@leanjunio do what you need to inside the then((res)... ?
Lean Junio
@leanjunio
Nov 14 2017 19:02
I’ll give that a try @JLuboff thanks
Ronique Ricketts
@RoniqueRicketts
Nov 14 2017 19:08
canvas secialists anyone know how to make draggable/resizable images in canvas?
Kristina
@kikidesignnet
Nov 14 2017 19:48
Does anyone know randelldawson? He appeared in my FreeCodeCamp post: https://forum.freecodecamp.org/t/ready-to-bang-my-head-against-the-wall-js-calculator-problems/159104/2
Jason Luboff
@JLuboff
Nov 14 2017 19:55
I've never seen him in this room, no
Kristina
@kikidesignnet
Nov 14 2017 20:03
He kinda feel like Yoda from Star Wars, saying confusing words and doesn't really answer what I really asked for....
But his words are helpful sometimes. but it kinda didn't really help with solving my problem...
How can I increase the size of this image using a click and drag event?
alpox
@alpox
Nov 14 2017 20:15

@kikidesignnet Very dirty but would work:

if(["+", "-", "*", "/"].includes(subMatharray[subMatharray.length-1])) {
      mainMath = subMatharray[subMatharray.length-2]
      subMatharray = subMatharray.slice(0, subMatharray.length-2);
    }

Before doing the calculations in addOperator

Ronique Ricketts
@RoniqueRicketts
Nov 14 2017 20:16
my img.onclick = function will not fire. What have I done wrong?
alpox
@alpox
Nov 14 2017 20:18
@kikidesignnet There would most likely be an easier way but your global variables have such names that i cannot get much of their sense :D
Kristina
@kikidesignnet
Nov 14 2017 20:18
@alpox Did you write the solution in codepen? May I ask for the link?
Ronique Ricketts
@RoniqueRicketts
Nov 14 2017 20:18
If I add an event listener on img for load it works but other events wont work.
Kristina
@kikidesignnet
Nov 14 2017 20:20
@alpox I just checked out your code. However when I tested "5+" and then "-", it doesn't work and it's same for "1+2+3" as well too..
Please feel free to ask me what you don't understand
alpox
@alpox
Nov 14 2017 20:21
@RoniqueRicketts Hmm yea thats because you add the events to the Image DOM element but the DOM element never gets added. You only use it for telling the canvas what image to draw and then throw away the DOM element. So your eventhandlers also go under with it.
You'd have to add click event handlers to the canvas
@kikidesignnet Whats the reason for having mainMath and subMatharray? What do those stand for? (Better variable names would be appropriate here)
Is there a special idea behind splitting those up?
@kikidesignnet Works for me with 5+ and then -.
@kikidesignnet But you're right, the other doesn't work.
May have to do with how you handle those variables
@kikidesignnet Also, equaltrue doesn't seem to have any meaning with that name
Kristina
@kikidesignnet
Nov 14 2017 20:26
@alpox mainMath is the Entry area. The one with big "0". It's where one press a number and it appears in the big entry area. subMatharray is the array in which you push both the numbers and the operators in the history area under the big "0".
Ronique Ricketts
@RoniqueRicketts
Nov 14 2017 20:26
@alpox So I should add a click even on the canvas itself?
alpox
@alpox
Nov 14 2017 20:26
@kikidesignnet I now see why it doesn't work for 1+2+3 - one cannot really check with subMatharray if some number was entered last or if it was a +
@RoniqueRicketts Yea unless you find a better method - you'd have to check stackoverflow for images on canvas. I believe most people refer to special elements in a canvas through frameworks
Ronique Ricketts
@RoniqueRicketts
Nov 14 2017 20:27
ok cool
@alpox thanks
Kristina
@kikidesignnet
Nov 14 2017 20:28
@alpox also equaltrue is needed for when one finished pressing an "=", but wanted to do more mathicational operations. For example, if I entered "1+2=" to get 3, I click on an operator again to get "3+" in the history area. So if equaltrue is true, I clear the subMatharray to get it ready for next one...
@alpox Did you check my forked codepen too? it's https://codepen.io/kikibres/pen/RjgJbz?editors=0010
alpox
@alpox
Nov 14 2017 20:30
@kikidesignnet Hmm with that setup its almost impossible to track if you entered a value right before or if it was set automatically to 0. Because you cannot track this, you have your problem to change the operator.
@kikidesignnet You can maybe add a new boolean which gets set to true if you enter an operator and to false when you enter a number. Or better, use a variable where you always save the last input done by the user.
Kristina
@kikidesignnet
Nov 14 2017 20:31
True, it was a difficult challenge. And in this forked codepen, It does work if I press "5+" and then "-", to get "5-" instead of "5+", but it still cause more problems if I entered "1+2+3"
oh
alpox
@alpox
Nov 14 2017 20:31
@kikidesignnet About your variables, please use describing variable names. equaltrue does not describe at all its meaning
Kristina
@kikidesignnet
Nov 14 2017 20:32
What do you suggest?
alpox
@alpox
Nov 14 2017 20:33
@kikidesignnet As variable name? inSubsequentCalculation
Kristina
@kikidesignnet
Nov 14 2017 20:34
What about equalBoolean?
alpox
@alpox
Nov 14 2017 20:35
@kikidesignnet Not at all. That would be as describing as just boolean and that only describes the type of the value the variable holds - nothing about its meaning
Kristina
@kikidesignnet
Nov 14 2017 20:38
equalOpCalculation, equalInSubsequentCalculation, checkIfEqualTrue
?
alpox
@alpox
Nov 14 2017 20:38
@kikidesignnet equal makes not much sense to put in the name. checkIfEqualTrue is not different than boolean in its meaning and is not describing at all either. equalOpCalculation doesn't tell me anything :-)
Kristina
@kikidesignnet
Nov 14 2017 20:40
but "equal" does make sense to me because it tells me to check if equal is true after "=" is pressed
alpox
@alpox
Nov 14 2017 20:41
@kikidesignnet Hmm but equal would tell if some values are equal to each other. Maybe equalPressed would then make more sense because like this the equal can only refer to the equality button. Without that context, equal doesn't tell any other reader something
Kristina
@kikidesignnet
Nov 14 2017 20:42
equalPressedBoolean?
alpox
@alpox
Nov 14 2017 20:43
@kikidesignnet Sidenote: When testing a boolean in an if you don't do something like == true or == false you'd just use if(inSubsequentCalculation) which just reads like if im in a state of a subsequent calculation
@kikidesignnet No. sorry :-)
Kristina
@kikidesignnet
Nov 14 2017 20:45
I tried if(equaltrue), but I feel more like 0_0. So I was planning to go with if(equaltrue == true) until every problem in my code is solved and then I'll clean it up and test if(equaltrue).
guess I'll just go with equalPressed
alpox
@alpox
Nov 14 2017 20:45
@kikidesignnet The problem with equaltrue is that the name says that "something" could be equal to true but it doesn't say at all what
@kikidesignnet Okay that can work even if i'd still not say its very well describing
But better than equaltrue
Kristina
@kikidesignnet
Nov 14 2017 20:47
thanks
alpox
@alpox
Nov 14 2017 20:48
np
Kristina
@kikidesignnet
Nov 14 2017 21:13
Hello?
@alpox hello?
alpox
@alpox
Nov 14 2017 21:16
@kikidesignnet Got a question? :-)
Kristina
@kikidesignnet
Nov 14 2017 21:19
I was trying to use one of your suggestions for using prevKey. Like if prevKey is "", process as normal, but if prevKey has operator, to do other method. But it's acting weird. Can I ask you to take a look at my forked Codepen, please? https://codepen.io/kikibres/pen/vWJxBW?editors=0010
alpox
@alpox
Nov 14 2017 21:23
@kikidesignnet prevKey is a good name :-) :+1: - so you only set prevKey if it wasn't set before and only clear it on calculator clear. You also have to set prevKey when you press a number on the calculator.
Kristina
@kikidesignnet
Nov 14 2017 21:26
so adding prevKey = mainMath; to function addNumber(keyitem)?
AbrisM
@AbrisM
Nov 14 2017 21:26
Hello, does anyone know how to italizice text in a newly created window following this format? https://codepen.io/StudentUser/pen/KyvWzO
I'm having problems getting the text italizied in the new window
alpox
@alpox
Nov 14 2017 21:27
@kikidesignnet I'd say prevKey = keyitem but that alone won't do it. You seem to have additional problems which i don't overview again because of all those flighting variables i don't know what they are for :D do a check of why the operators are not added to subMatharray anymore. Or is it finalArray now?
Kristina
@kikidesignnet
Nov 14 2017 21:29
Yeah, It's a bit more messed up now because I thought that it was a good idea to separate numbers and operators in different arrays and concat them together in finalArray. I might have to go back to fix that...
alpox
@alpox
Nov 14 2017 21:30
@kikidesignnet Yea that gets pretty confusing
Kristina
@kikidesignnet
Nov 14 2017 21:31
What I was trying to do is to push mainMath in the array, then do something with operators. If all checks out, push all in final array.... but apparently it didn't work...
Moisés Man
@moigithub
Nov 14 2017 21:33
@AbrisM myWindow.document.querySelector('p').innerHTML='<em>bla bla</em>';
or use getElementbyTagname (which returns a node list) n iterate through all of those, n change it
alpox
@alpox
Nov 14 2017 21:34
@kikidesignnet Thats no bad idea. But you could keep around the current operator as a single value (Not in an array) and it can be changed through pressing the operator and it only gets applied to the finalArray when you press the next number or =
That would be a very valid solution to this problem
Kristina
@kikidesignnet
Nov 14 2017 21:40
umm... it seems that I might understand this better if it's in a code. Anyway, as I see in my JS Calculator 4, the numbers works, but the operators doesn't show up. So in other words, assign keyitem to a value??
Marius Nicolae
@bytao7mao
Nov 14 2017 21:43
hi guys, i have a little issue, im trying to link in my JSON some objects
does someone here have some experience?
Kristina
@kikidesignnet
Nov 14 2017 21:45
@bytao7mao I might. What are you working on?
Marius Nicolae
@bytao7mao
Nov 14 2017 21:56
@kikidesignnet hi
Kristina
@kikidesignnet
Nov 14 2017 21:57
hey
Marius Nicolae
@bytao7mao
Nov 14 2017 21:57
im working on some condition, i want to link my winner or loser ID with country ID
this is my code
the logic is: if points of x.inv is > than x.def (see var x) then link the ID with countries ID (var y)
i get this now but it is not ok :)) because i getting only the index 1 from all
"85 > 37 Winner is: Brazil"
Stephen James
@sjames1958gm
Nov 14 2017 22:09
Seems like you can used countries as a object - not array of values.
var c = JSON.parse(ourRequest.responseText).countries;
// Then use the id from the inv and def to get the country object /name
 console.log(c[x[1].inv.id].name + " > " + c[x[1].def.id].name);
Although that gave me Japan > Montenegro - which doesn't seem correct ;(
Marius Nicolae
@bytao7mao
Nov 14 2017 22:11
yeah, i used objects
=))
haha
i shouldn't use object.val or key ?
AbrisM
@AbrisM
Nov 14 2017 22:13
@moigithub Hi Moise, using .querySelector came up with no results https://codepen.io/StudentUser/pen/KyvWzO
Moisés Man
@moigithub
Nov 14 2017 22:16
open ur BROWSER DEVTOOLS console and check if u have any errors
F12 on most browsers to open devtools @AbrisM
iso
@iso1048
Nov 14 2017 22:19
Hi. What IDE do you guys recommend using? I was thinking about using Atom.
Jason Luboff
@JLuboff
Nov 14 2017 22:19
@gothamknight I use Atom. I like it a lot. Others like VS Code. Others like Sublime, etc. All preference
Ronique Ricketts
@RoniqueRicketts
Nov 14 2017 22:20
Atom is cool. I like the pretty colours :)
@JLuboff where have you been all day? Man I needed some help with some canvas and you disappeared. You and that @sjames1958gm (angry fist)
:smile:
Jason Luboff
@JLuboff
Nov 14 2017 22:21
@RoniqueRicketts Oh..I was here..but.. I don't know enough canvas to have answered your question
Ronique Ricketts
@RoniqueRicketts
Nov 14 2017 22:23
@JLuboff ok you sneaky lurker. hehehe. Well I figured part A. of my question now the harder part is left.
well I can skew my image hahaha. but to make it respond to touch idk how to do that as none of my event functions are not firing.
iso
@iso1048
Nov 14 2017 22:24
@JLuboff @RoniqueRicketts thanks. Atom it is!
CamperBot
@camperbot
Nov 14 2017 22:24
gothamknight sends brownie points to @jluboff and @roniquericketts :sparkles: :thumbsup: :sparkles:
:star2: 2261 | @jluboff |http://www.freecodecamp.org/jluboff
:cookie: 405 | @roniquericketts |http://www.freecodecamp.org/roniquericketts
Ronique Ricketts
@RoniqueRicketts
Nov 14 2017 22:26
@gothamknight yw man.
AbrisM
@AbrisM
Nov 14 2017 22:29
@moigithub Don't see any errors
Moisés Man
@moigithub
Nov 14 2017 22:30
did u open new window.. enter text.. and finally tried to italicize it ?? @AbrisM
AbrisM
@AbrisM
Nov 14 2017 22:30
Ah, except italicize not found
Yes, I have tried that
Moisés Man
@moigithub
Nov 14 2017 22:30
soo.. if red.. then its an error....
AbrisM
@AbrisM
Nov 14 2017 22:31
reference error
Moisés Man
@moigithub
Nov 14 2017 22:31

it says.. there are NO (function) named Italics

Italics is not defined
<button onclick="Italics();"> Use This to Change to Italics</button>

AbrisM
@AbrisM
Nov 14 2017 22:32
Yes
Strange, isn't creating a function declaring it?
Moisés Man
@moigithub
Nov 14 2017 22:34
.. remove that extra s
or add an s on function Italic(){...
AbrisM
@AbrisM
Nov 14 2017 22:35
I've removed the extra s
now it says myWindow is undefined
Moisés Man
@moigithub
Nov 14 2017 22:36
cuz after the code changes... codepen reloaded..
so global variables (myWindow) reseted (dont contains any reference )
AbrisM
@AbrisM
Nov 14 2017 22:38
hmm
Moisés Man
@moigithub
Nov 14 2017 22:38
.. press ALL buttons again..
create new window add text.. italic
AbrisM
@AbrisM
Nov 14 2017 22:39
Okay, I see now it creates the 'bla bla' after pressing a new window
but how do I have it where it basicually inputs whatever the user puts in?
Moisés Man
@moigithub
Nov 14 2017 22:40
store the previous <p> content first.. then wrap it on <em> tag
AbrisM
@AbrisM
Nov 14 2017 22:40
confused hahaha
Moisés Man
@moigithub
Nov 14 2017 22:41
let previousContent = mywindow.document... etc .innerHTML;
mywindow.document.. etc. innerhtml = '<em>'  + previous +  '</em>'
FlashHero
@FlashHero
Nov 14 2017 22:44
Am i allowed to add extra parameters in an function
Aleksander Gębicki
@Takumar
Nov 14 2017 22:44
Hello campers,
this weekend (17-19 November) CodeSchool is offering free learning for everybody.
There is much interesting content, so tell your family you are absent ;-)

CodeSchool - free weekend

Jason Luboff
@JLuboff
Nov 14 2017 22:44
@FlashHero Is it for an FCC challenge? IF so, then no, don't do that
FlashHero
@FlashHero
Nov 14 2017 22:46
@JLuboff the guide for the permutation algorithm has extra parameters, so i was confused
@JLuboff thanks though
CamperBot
@camperbot
Nov 14 2017 22:46
flashhero sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2262 | @jluboff |http://www.freecodecamp.org/jluboff
Moisés Man
@moigithub
Nov 14 2017 22:46
@AbrisM ... press the buttons again... to see if it work like it should... if not.. then u missed something :)
AbrisM
@AbrisM
Nov 14 2017 22:51
It shows the italics so it is working but it doesn't show the results from "Insert Your Text Here", just the default of what has been placed between the <em> tags
Moisés Man
@moigithub
Nov 14 2017 22:51
i posted 2 lines above.. u only added 1 to ur code...
ofc.. its incomplete.. cuz im lazy ... but should give u an idea
previous .. should be previousContent variable name
AbrisM
@AbrisM
Nov 14 2017 22:53
Okay, I have edited the code https://codepen.io/StudentUser/pen/KyvWzO to include the two lines
Hahaha, this is a new concept for me but I appreciate the help :)
Moisés Man
@moigithub
Nov 14 2017 22:54
    function Italic(){
 let previousContent = mywindow.document.querySelector('p').innerHTML;     
myWindow.document.querySelector('p').innerHTML='<em>'   + previousContent    +  '</em>';    

    }

or

function Italic(){
    let theElement = mywindow.document.querySelector('p');
    let previousContent = theElement.innerHTML;     
    theElement.innerHTML = '<em>'   + previousContent    +  '</em>';    
 }

same thing

AbrisM
@AbrisM
Nov 14 2017 23:01
Hmm nope, also encounted caught reference errors (2) https://codepen.io/StudentUser/pen/KyvWzO
Moisés Man
@moigithub
Nov 14 2017 23:05
@AbrisM javascript is case sensitive.. make sure u use the SAME variables names all the rest of ur code does...
mywindow should be myWindow (according to the rest of ur code)
dont just blind copy /paste ;)
AbrisM
@AbrisM
Nov 14 2017 23:08
Alright, I will go through it again
small mywindow
Wait a second, Window is capitalized :)
Yes, I see that it works
@moigithub Thanks!
CamperBot
@camperbot
Nov 14 2017 23:12
abrism sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3707 | @moigithub |http://www.freecodecamp.org/moigithub
dyon3334
@dyon3334
Nov 14 2017 23:23
does anyone now how i can get every result on a new line ?
var data ="attributes baseURI childNodes firstChild lastChild localName namespaceURI nextSiblingv nodeName nodeType nodeValue ownerDocument parentNode prefix previousSibling textContent Node Methods appendChild() cloneNode() compareDocumentPosition() getFeature(feature,version) getUserData(key) hasAttributes() hasChildNodes() insertBefore() isDefaultNamespace() isEqualNode() isSameNode() isSupported() lookupNamespaceURI() lookupPrefix() normalize() removeChild() replaceChild() setUserData(key,data,handler)"
function converter(a){
var b = a.split(" ");
function p (){ 
var c = b.join("====")
document.write(c)
var c = ""
}
b.forEach(p);
}
now i get this : attributes====baseURI====childNodes====firstChild====lastChild====localName====namespaceURI====nextSiblingv====nodeName====nodeType====nodeValue====ownerDocument====parentNode====prefix====previousSibling====textContent====Node====Methods====appendChild()====cloneNode()====compareDocumentPosition()====getFeature(feature,version)====getUserData(key)====hasAttributes()====hasChildNodes()====insertBefore()====isDefaultNamespace()====isEqualNode()====isSameNode()====isSupported()====lookupNamespaceURI()====lookupPrefix()====normalize()====removeChild()====replaceChild()====setUserData(key,data,handler)
Moisés Man
@moigithub
Nov 14 2017 23:25
wrap each values in a <p> element
dyon3334
@dyon3334
Nov 14 2017 23:25
and i want each resul on a new line
Moisés Man
@moigithub
Nov 14 2017 23:26
so it ends up like <p>attributes</p><p>baseURI</p>
since paragraph tag is a block element.. it will shows each on its own line
...also forEach callback function have some parameters u could use...
function p(value) {
     // .... that will be each/every value of  "b"
     document.write(  '<p>'   +    value      +      '</p>' );
}
b.forEach(p);
dyon3334
@dyon3334
Nov 14 2017 23:31
@moigithub thanks woow i was forgetten the p ellement
CamperBot
@camperbot
Nov 14 2017 23:31
dyon3334 sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3710 | @moigithub |http://www.freecodecamp.org/moigithub
AbrisM
@AbrisM
Nov 14 2017 23:35
Now to add a header button