These are chat archives for FreeCodeCamp/HelpJavaScript

5th
Nov 2017
Michael
@learicist
Nov 05 2017 00:51
Hello all. I am trying to finish up the Simon game to print out the certificate for front end developer. I have a question about a specific part of my game code, and I cannot understand what is happening. Any help would be greatly appreciated. I can get the game to reload and start at the beginning until the player begins to play the game. Up until that point, the workaround of window.location.href works perfectly, since codepen erases location.reload(). My presumption is that the section of the code that takes over once the user begins to click their color choices is somehow preventing the ability of the reset button to do it's job. I have spent days searching for it, and am happy to be made to feel a fool once it is found. Thank you ahead of time.
Tom
@moT01
Nov 05 2017 00:58
@learicist you think it might be a codepen problem, did you try locally?
Michael
@learicist
Nov 05 2017 01:01
yes. it works perfectly locally @moT01
at any time during the game, i can reload the page. but in codepen. it does not work once the user has started to choose colors to click @moT01. however, it will work successfully before the user clicks, so i know that the code to reload the page can be accessed and triggered.
korzo
@korzo
Nov 05 2017 01:02
@learicist I think it's related to the fact, that on codepen your code runs inside the iframe
Tom
@moT01
Nov 05 2017 01:03
@learicist you can put the code up on github, and create a project on glitch.com for a live version, should work and you can avoid codepen
wont have to change any code
or you can run it with github pages
Michael
@learicist
Nov 05 2017 01:04
i will try that, thank you. i believe in order to submit it to FCC and complete the front end developer certificate, it has to be linked from codepen
Tom
@moT01
Nov 05 2017 01:04
no, just a link to a live demo should work
pretty sure
Michael
@learicist
Nov 05 2017 01:04
ok excellent i will try. thank you!
Tom
@moT01
Nov 05 2017 01:05
settings tab on the far right of your repo
probly the easiest
VinoL
@VinoL
Nov 05 2017 03:54
Hello?
abraham anak agung
@padunk
Nov 05 2017 04:20
Hello... good afternoon everyone
yofri
@yofriadi
Nov 05 2017 04:47
hey guys, need help in ejs
how to insert selected in option tag using ejs
<select name="subjectId">
  <% rowSubject.forEach(rowSubject => { %>
    <option value="<%= rowSubject.id %>"
       <% if (rowSubject.id === rowTeacher.id) { %>
          <%= 'selected' %>  // this dont work
        <% } %> >
            <%= rowSubject.subject_name %>
     </option>
   <% }) %>
</select>
yofri
@yofriadi
Nov 05 2017 05:07
mm ok solved by myself
段段
@ddkun
Nov 05 2017 05:27
按照下面的顺序,并且用空格来分割:
反斜杠 制表符 退格符 回车符 换行符 并把它赋值给变量 myStr
Vincent Chho
@koalavc
Nov 05 2017 07:43
can someone help me? im trying to make a pure javascript to-do app. i have a
button where the user would add a item in the input field. but when the input
field is empty it would spout out a blank <li>.
this is my codepen
Tiago Correia
@tiagocorreiaalmeida
Nov 05 2017 10:11
@alpox portugal :D
@koalavc that codepen is empty
that's not the url you wanna give :D
hillsie
@Hillsie
Nov 05 2017 11:06
@GitHub-Henry Thanks, yip same one.
CamperBot
@camperbot
Nov 05 2017 11:06
hillsie sends brownie points to @github-henry :sparkles: :thumbsup: :sparkles:
:cookie: 469 | @github-henry |http://www.freecodecamp.com/github-henry
Alex
@alexandrupintilei
Nov 05 2017 13:03
Can someone tell me why group class resize all cols? https://codepen.io/balexoy/pen/YEqooG
shivam gupta
@shivamg11000
Nov 05 2017 13:14
@alexandrupintilei can you elaborate better?
Alex
@alexandrupintilei
Nov 05 2017 13:23
@shivamg11000 I want to use group and deck classes for this album. https://codepen.io/balexoy/full/YEqooG/
shivam gupta
@shivamg11000
Nov 05 2017 13:35
@alexandrupintilei I think you remove the colunms and use card elements directly as child tags in card-deck
FlashHero
@FlashHero
Nov 05 2017 15:00
@koalavc you can check if the input field is empty and if it is don't add the <li> to wherever your saving it to
Bryan Reese
@breese8009
Nov 05 2017 15:56
why in react when I set the value of an input in react it doesnt let me touch that value anymore?
the input becomes dead
:skull:
Razvan Jackson
@RazvanJackson
Nov 05 2017 16:20
Who knows C++ here?
Spyrantis Theodoros
@thodorisanta
Nov 05 2017 16:29
how can i make athe js of 5 numbers var x = [1,2,3,4,5]; that will return me one number per second?
Razvan Jackson
@RazvanJackson
Nov 05 2017 16:30
@thodorisanta
You have an array of 5 numbers right?
Spyrantis Theodoros
@thodorisanta
Nov 05 2017 16:30
yeah
Razvan Jackson
@RazvanJackson
Nov 05 2017 16:30
``` var x=[1,2,3,4,5];
Spyrantis Theodoros
@thodorisanta
Nov 05 2017 16:32
but note that i add numbers to this array so next time it might have 6 numbers instead of 5
to be more specific i need this for the simon game project so since i start with an empty array and i slowly add numbers to it. i want it to return me every time the numbers of the array from the begging. meaning if arr x has [1,2] it will return me the value 1 and after one second the value 2 same for x = [1,2,3,etc]
Moisés Man
@moigithub
Nov 05 2017 16:37
per second.. use setInterval
to add numbers u can push to array
let myArr = [];
iHandler = setInterval(function(){
    myArr.push( 1 );
}, 1000); // miliseconds
that will push 1 every 1 second
if u want random values.. u can use Math.random
Razvan Jackson
@RazvanJackson
Nov 05 2017 16:42
````
var x=[1,2,3,4,5];

setInterval(function(){
    let r = Math.floor(Math.random() * (x.length - 1) + 1);
    console.log(r);
  x.push(x.length+1);
  console.log(x);
},1000);
smth like this
?
@thodorisanta
Moisés Man
@moigithub
Nov 05 2017 16:42
but.. for simon game u should not do that, but control (user/computer) turns
and ONLY add values when comp. turn
AbrisM
@AbrisM
Nov 05 2017 16:54
Hi all!
Razvan Jackson
@RazvanJackson
Nov 05 2017 16:57
@AbrisM Hi
Addison
@addisonday
Nov 05 2017 17:00
I'm doing this beta challenge, but I am not sure what my mistake is. Challenge link is: https://beta.freecodecamp.org/en/challenges/object-oriented-programming/override-inherited-methods
My code is:
function Bird() { }

Bird.prototype.fly = function() { return "I am flying!"; };

function Penguin() { }
Penguin.prototype = Object.create(Bird.prototype);
Penguin.prototype.constructor = Penguin;

// Add your code below this line
Penguin.prototype.fly = function(){
  console.log("Alas, this is a flightless bird.");
};

// Add your code above this line

let penguin = new Penguin();
console.log(penguin.fly());
Moisés Man
@moigithub
Nov 05 2017 17:05
probably u should return a string... similar to Bird.prototype.fly ??
instead of console.log ? @addisonday
Addison
@addisonday
Nov 05 2017 17:05
@moigithub Good catch! I'll give that a try!
@moigithub That was it! Thank you! Only gave me a headache for about 3 minutes
CamperBot
@camperbot
Nov 05 2017 17:06
addisonday sends brownie points to @moigithub :sparkles: :thumbsup: :sparkles:
:star2: 3702 | @moigithub |http://www.freecodecamp.com/moigithub
Moisés Man
@moigithub
Nov 05 2017 17:06
:)
Daniel Romero
@Ranacode
Nov 05 2017 17:55
Any idea to refactor this code?
function solution(str){
  let splitted = [];
  if (str.length % 2 === 0) {
    for (let i = 0; i < str.length; i+=2) {
     splitted.push(str.slice(i, i+ 2))
  }
  } else {
     for (let i = 0; i < str.length; i+=2) {
      if (i === str.length - 1) {
        splitted.push(str.slice(i, i+2) + "_")
      } else {
             splitted.push(str.slice(i, i+ 2))
      }
    }
  }
  return splitted;
}
I passed the kata on codewars but it seems so ugly
The function must split the string into character pairs like "solution("refactor") // ["re", "fa", "ct", "or"]
and if the length of the string is odd, should add an "_" in the last pair
Moisés Man
@moigithub
Nov 05 2017 18:10
function solution(str){
  let splitted = [],
      newStr = str;
    if (str.length % 2 !== 0) {
       newStr = str + "_";
    }

     for (let i = 0; i < newStr.length; i+=2) {
             splitted.push(newStr.slice(i, i+ 2))
    }
  return splitted;
}
@Ranacode
Lorena
@lore-code
Nov 05 2017 18:15

I'm triying to do the pig latin algorithm. The issue I am having is I can't figure out how to join the array. I've tried array.join() but nothing I'm stuck here...
function translatePigLatin(str) {

var splits = str.split("");

var vowels=["a","e","i","o","u"];

var exists = vowels.indexOf(splits[0]);

var newArr=[];

if(exists===-1) {

str.substr(1);

newArr.push(str.substr(1)+splits);

console.log(newArr);

}

}

translatePigLatin("pig");

Moisés Man
@moigithub
Nov 05 2017 18:15
similar to split.. join can use values
.join("")
if u do join().. by default is ","
Lorena
@lore-code
Nov 05 2017 18:24
I want to join this should I do a new Array? ["igp,i,g"]
Spyrantis Theodoros
@thodorisanta
Nov 05 2017 18:28
@moigithub @RazvanJackson
check my js after line 77(which is the function call)
the program is supposed to (when you click the on switch first thenclick the start button, to "light-up" a random button. and once you click that button to show you the first button and then a next one randomly) but instead in only shows you the new one.
https://codepen.io/oshikurou/pen/vWGoee?editors=0011
Razvan Jackson
@RazvanJackson
Nov 05 2017 18:30
@thodorisanta Sorry i can't now. Tommorrow i have a test
Gotta recap
Spyrantis Theodoros
@thodorisanta
Nov 05 2017 18:52
@RazvanJackson ok
tarun47900
@tarun47900
Nov 05 2017 19:06
Hii
See cod3 what's wrong
Alex
@alexandrupintilei
Nov 05 2017 19:11
Can someone help me to make a slider like this,except,when img should RUN 1 -by- 1 https://www.youtube.com/watch?v=SAyLQVR1t5s
AbrisM
@AbrisM
Nov 05 2017 21:51
Hi all
AbrisM
@AbrisM
Nov 05 2017 21:58
Is the carosel video a HTML/CSS file?
alpox
@alpox
Nov 05 2017 22:03
@AbrisM Its solved
AbrisM
@AbrisM
Nov 05 2017 22:03
Alright, looked like an HTML file though
I'm here for the Java though ;3
alpox
@alpox
Nov 05 2017 22:06
@AbrisM Java? :D even though some people here know java, its mainly javascript here ;)
AbrisM
@AbrisM
Nov 05 2017 22:06
Where do I find the Java room?
alpox
@alpox
Nov 05 2017 22:06
@AbrisM There is none ^^
AbrisM
@AbrisM
Nov 05 2017 22:06
I do Javascript too but it would be nice to know the room
Wow, hehehe
alpox
@alpox
Nov 05 2017 22:07
@AbrisM Freecodecamp is about web dev - java is considered backend here, so HelpBackend would be the best fit - although they use mostly NodeJS
And the gitter chats are already lacking attention because they took the reference to it down from the FCC site - so there is not much happening anymore
AbrisM
@AbrisM
Nov 05 2017 22:08
Ahh wow so it's like ghost-town in some of the chats
alpox
@alpox
Nov 05 2017 22:08
Yea a little
There are still some few people ghosting around though :D
AbrisM
@AbrisM
Nov 05 2017 22:17
It's quiet here haha
CallMeOrange
@EgnaroDev
Nov 05 2017 22:19
Hey guys, have you heard anything about beta fCC?
AbrisM
@AbrisM
Nov 05 2017 22:21
Nope
CallMeOrange
@EgnaroDev
Nov 05 2017 22:21
Hm..
AbrisM
@AbrisM
Nov 05 2017 22:21
FCC? I assume that stands for FreeCodeCamp and not the official FCC :D
What's the difference between the beta FCC and this one?
CallMeOrange
@EgnaroDev
Nov 05 2017 22:23
Well... I guess you could say they are building new fCC
AbrisM
@AbrisM
Nov 05 2017 22:23
With Discord chats instead of glitter?
Gitter*
CallMeOrange
@EgnaroDev
Nov 05 2017 22:23
I don't know anything about it
Tiago Correia
@tiagocorreiaalmeida
Nov 05 2017 23:02
anyone around that is used to mongodb?
mstellaluna
@mstellaluna
Nov 05 2017 23:27

@AbrisM The difference between the beta and this one is that the beta is currently under construction and logins have been disabled during this time. You can do the beta but it will not issue out certificates nor can you save your progress. The curriculum is also different, it has been expanded in beta.

Concerning discord FCC chats, those are non-official FCC chat rooms. The rooms here in gitter are the official rooms.