These are chat archives for FreeCodeCamp/HelpJavaScript

11th
Nov 2017
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 00:01
almost there :D
that was only of the first things that messed my ming tough
mind
Jason Luboff
@JLuboff
Nov 11 2017 00:03
I should use regex.
fuuuccckkk
That handled the case issue, but not the random characters
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 00:07
Yeah after see the solutions I taught that too xd
Jason Luboff
@JLuboff
Nov 11 2017 00:07
oh wait..thats becuase of ? hmm
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 00:08
what do you mean?
Jason Luboff
@JLuboff
Nov 11 2017 00:08
you need to escape ? in regex
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 00:10
dont think so
you just have to check for matches
Jason Luboff
@JLuboff
Nov 11 2017 00:11
Yup. Got my solution
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 00:11
you dont even need to escape it
Can I see it?
Jason Luboff
@JLuboff
Nov 11 2017 00:12
const firstNonRepeatingLetter = s => s.split('').filter((el, i, arr) => {
  let reg = /\W/g.test(el) ? new RegExp('\\' + el, 'gi') : new RegExp(el, 'gi');
  if(arr.join('').match(reg).length === 1){
  return el;
  };
})[0] || ''
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 00:12
function firstNonRepeatingLetter(s) {
  if(s.length === 0) return "";
  let lowerCase = s.toLowerCase().split("");
  for(let i = 0; i < lowerCase.length; i++){
    if(lowerCase.filter(ele=>ele === s[i].toLowerCase()).length === 1){
      return s.charAt(i);
    }
  }
  return "";
}
this is mine what you think of it?
btw good one @JLuboff I only tough of regex after ending and see others solutions ... just the usual :D
Jason Luboff
@JLuboff
Nov 11 2017 00:13
I think it gets the job done :D I don't like to critique others code only becuase I know my code isn't ideal in the first place usually lol
Ah.. I see @forkerino solution he was going to route I originally was thinking using indexOf and lastIndexOf
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 00:15
I could have avoided the filter by using the match on the loop current value and then check length
but well there's always alot of ways to go :D
Diego Mayer
@Chrono79
Nov 11 2017 00:19
function firstNonRepeatingLetter(s) {
  var sl = s.toLowerCase();
  for (var i=0; i<sl.length; i++) {
    if (sl.indexOf(sl[i])===sl.lastIndexOf(sl[i])) return s[i];
  }
  return "";
}
Like this?
Jason Luboff
@JLuboff
Nov 11 2017 00:24
@Chrono79 That was like my original solution (to an extent) but the tolowercase I was doing inside the indexOf condition. Think it was screwing it upo
alpox
@alpox
Nov 11 2017 00:27
@tiagocorreiaalmeida @JLuboff
function firstNonRepeatingLetter(s) {
  const found = s.replace(/(.)(.*?)\1(.*)\1?/gi, "$2$3")
  return found === s ? found[0] || '' : firstNonRepeatingLetter(found);
}
Jason Luboff
@JLuboff
Nov 11 2017 00:27
@alpox You're sick.
alpox
@alpox
Nov 11 2017 00:27
@JLuboff Nah
:D
Jason Luboff
@JLuboff
Nov 11 2017 00:28
recursion. replace.
Fuck man. Thats just nasty.
:P
alpox
@alpox
Nov 11 2017 00:28
Thats yolo :D
I should be in bed though ^^ have fun and bb :D
Jason Luboff
@JLuboff
Nov 11 2017 00:29
See ya Monday
alpox
@alpox
Nov 11 2017 00:29
Off over weekend? ;-)
Jason Luboff
@JLuboff
Nov 11 2017 00:29
Yup!
I haven't been doing any programming over the weekend
Just pick back up when I'm at work heh
alpox
@alpox
Nov 11 2017 00:30
Ok :D chilling the brain is good
Cya monday then
Jason Luboff
@JLuboff
Nov 11 2017 00:30
:wave:
elpatron17
@elpatron17
Nov 11 2017 01:27
hello guys
Christopher Brown
@ChrisBrownie55
Nov 11 2017 01:34
@elpatron17 Hi 👋
Maximino V. Jardin III
@ma5one1
Nov 11 2017 01:52
Hey folks!
Just upgraded to PRO on codepen and wondering if the URL libs copied are active soon as you click copy??
AbrisM
@AbrisM
Nov 11 2017 02:42
They should be @ma5one1
and grats
Maximino V. Jardin III
@ma5one1
Nov 11 2017 03:08
@AbrisM thanks!
CamperBot
@camperbot
Nov 11 2017 03:08
ma5one1 sends brownie points to @abrism :sparkles: :thumbsup: :sparkles:
api offline
I can't understand the meaning of this title.Why is that answer wrong
Allister
@AlyxMoon
Nov 11 2017 04:30

@inputherf

In this case, note the instruction:
请注意,在英文中,句中的单词是必须用空格来分隔的
In English:
Please note that in English, the words in a sentence must be separated by a space

You are missing the spaces between words. If I called your function like this:
wordBlanks("dog", "big", "ran", "quickly");

I would get:
dogbigranquickly

Which is incorrect in English without spaces (and grammatically incorrect, but that's not as important :) ).
What I SHOULD get is:
dog big ran quickly

Fabien SHAN
@X140hu4
Nov 11 2017 05:01
Hi guys. I am working on the twitch tv project. I managed to get the data from the fCC workaround for one channel, but I have issues working on a list of channels in an array.
Fabien SHAN
@X140hu4
Nov 11 2017 05:24
So it seems to be making the requests correctly but only the last one completes?...
Bhoomi Khanderia
@bhoomikhanderia
Nov 11 2017 05:43
Hi guys!
How can I connect to an api using javascript?
Brian
@BrianCodes33
Nov 11 2017 06:04
@Bhoomi-Github you have many different options. check out fetch
bahaa aldin
@bahaa-al-deen
Nov 11 2017 06:05
@sjames1958gm @Blauelf @ChrisBrownie55
i don't know if that's what you were trying to explain to me or not
but i got it to work
i made the function leak the index each itiration to a global array
and then split and join each 0 and take the last index before the 0
that way i stop when i find what i want
Long Nguyen
@longnt80
Nov 11 2017 07:14
@X140hu4 you need to copy your main.css to the CSS window of Codepen
you also only need to copy the code inside of body tag to HTML window
Bhoomi Khanderia
@bhoomikhanderia
Nov 11 2017 08:02
Hi guys!
How can I connect to an api using javascript?
Markus Kiili
@Masd925
Nov 11 2017 08:15
@Bhoomi-Github You can do that with an AJAX request.
Bhoomi Khanderia
@bhoomikhanderia
Nov 11 2017 09:06

<!DOCTYPE html>

<html>
<head>
<title>Hi</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">

<script>

// const url = 'http://alintacodingtest.azurewebsites.net/api/Movies';
// fetch(url) // Call the fetch function passing the url of the API as a parameter
// .then(function() {
// // Your code for handling the data you get from the API
// })
// .catch(function() {
// // This is where you run code if the server returns any errors
// });
// function UserAction() {
// var xhttp = new XMLHttpRequest();
// xhttp.open("GET", "http://alintacodingtest.azurewebsites.net/api/Movies", true);
// xhttp.setRequestHeader("Content-type", "application/json");
// xhttp.send();
// var response = JSON.parse(xhttp.responseText);
// }

function getJSONP(url, success) {

var ud = '_' + +new Date,
script = document.createElement('script'),
head = document.getElementsByTagName('head')[0]
|| document.documentElement;

window[ud] = function(data) {
head.removeChild(script);
success && success(data);
};

script.src = url.replace('callback=?', 'callback=' + ud);
head.appendChild(script);

}

getJSONP('http://alintacodingtest.azurewebsites.net/api/Movies', function(data){
console.log(data.status);
});

</script>
</head>
<body>
<!-- <button type="submit" onclick="UserAction()">Search</button> -->
</body>
</html>

What am I doing wrong here?
Adel
@AdelMahjoub
Nov 11 2017 09:13
@X140hu4 make recursive requests to the api
Fabien SHAN
@X140hu4
Nov 11 2017 10:06
@AdelMahjoub So using a recursive function, requests will fire after the previous has finished?
Adel
@AdelMahjoub
Nov 11 2017 10:09
@X140hu4 set an iterator to 0, define a function taht make an xhr request and take a callback , call that function, check the iterator against your array length, inside the callback increment the iterator and call the function again
@X140hu4 or you can emit an event after the xhr callback
@X140hu4 outside the xhr callback, listen to that event
@X140hu4 you can also send multiple xhr requests, inside the loop create new XMLHttpRequest for each iteration
@X140hu4 but it will be very hard to track them :smile:
Adel
@AdelMahjoub
Nov 11 2017 10:16
@X140hu4 or even better, use axios.all https://github.com/axios/axios
@X140hu4 if you are using codepen, axios cdn https://unpkg.com/axios/dist/axios.min.js
Fabien SHAN
@X140hu4
Nov 11 2017 10:19
@AdelMahjoub Thanks! I will have a look then :)
CamperBot
@camperbot
Nov 11 2017 10:19
x140hu4 sends brownie points to @adelmahjoub :sparkles: :thumbsup: :sparkles:
:cookie: 616 | @adelmahjoub |http://www.freecodecamp.com/adelmahjoub
Adel
@AdelMahjoub
Nov 11 2017 10:21
@X140hu4 using axios.all is the easiest way, but I think that a jquery ajax request inside jquery foreach or each, will make async requests, not sure
Fabien SHAN
@X140hu4
Nov 11 2017 10:22
I try to use pure javascript as much as I can
Adel
@AdelMahjoub
Nov 11 2017 10:23
@X140hu4 yes, no need of jquery
so here it mentions if you care about performance you should avoid setting the [[Prototype]] of an object. Instead, create a new object with the desired [[Prototype]] using Object.create()., if I want HTMLElement.prototype.on = addEventListener; how I could use Object.create instead
Adel
@AdelMahjoub
Nov 11 2017 11:11
@X140hu4 you can use CustomEvent, no need for recursive calls and third party modules
Fabien SHAN
@X140hu4
Nov 11 2017 11:32
oh thanks ! I will look into it some other time ^^
Long Nguyen
@longnt80
Nov 11 2017 12:57
@X140hu4 when looking at your problem, I found this: https://stackoverflow.com/questions/11178177/when-sending-multiple-xmlhttprequests-only-the-last-request-returns-success
not js but it should help to understand why only the last request was returned
Fabien SHAN
@X140hu4
Nov 11 2017 13:34
@longnt80 Oh wow... Thanks ! The for loop was iterating through the same xhr object then... in your modified code it is creating a new xhr object for each iteration right?
CamperBot
@camperbot
Nov 11 2017 13:34
x140hu4 sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
api offline
Long Nguyen
@longnt80
Nov 11 2017 13:35
@X140hu4 yeah, that's it
Adel
@AdelMahjoub
Nov 11 2017 13:38
If you want to use custom events, this is the full code
window.addEventListener('DOMContentLoaded', function() {

  var CHANNELS = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"];
  var URL = 'https://wind-bow.glitch.me/twitch-api/channels/';

  var xhr = new XMLHttpRequest();
  var iterator = 0;
  var requests = CHANNELS.length;
  var data = [];
  var next = new CustomEvent('next'); // Got a response
  var done = new CustomEvent('done'); // Got all responses

  /**
   * Parse a string to a javascript object
   * @param {string} string 
   * @return {object}
   */
  function json(text) {
    return JSON.parse(text);
  }

  /**
   * Store an object in the data array
   * @param {object} object 
   * @return {void}
   */
  function storeData(object) {
    data.push(object);
  }

  /**
   * Send a GET request to an url
   * @return {void}
   */
  function get(url) {
    xhr.onreadystatechange = function() {
      if(this.readyState === XMLHttpRequest.DONE) {
        if(this.status === 200) {
          storeData(json(this.response));
          // Emit `next` event when got a response
          window.dispatchEvent(next); 
        } else {
          throw new Error(this.statusText);
        }
      }
    }
    xhr.open('GET', url, true);
    xhr.send(null);
  }

  // Listen to `next` events
  window.addEventListener('next', function() {
    iterator++;
    // Check if all requests are done
    if(!(requests - iterator)) {
      // Emit `done` event
      return window.dispatchEvent(done);
    }
    // Else, GET request for the next channel 
    return get(URL + CHANNELS[iterator]);
  });

  // Listen to `done` events
  window.addEventListener('done', function() {
    console.log(data);
    /* Handle the data */
  });

  // Start requesting
  get(URL + CHANNELS[iterator]);

});
Long Nguyen
@longnt80
Nov 11 2017 13:39
@AdelMahjoub :+1:
@AdelMahjoub thanks man
CamperBot
@camperbot
Nov 11 2017 13:42
longnt80 sends brownie points to @adelmahjoub :sparkles: :thumbsup: :sparkles:
api offline
Adel
@AdelMahjoub
Nov 11 2017 13:43
@longnt80 you have more control, over handling the data on the fly
Long Nguyen
@longnt80
Nov 11 2017 13:45
@AdelMahjoub how do you know about this? Is this a often used technique for async request?
I'd try to use Promise
Adel
@AdelMahjoub
Nov 11 2017 13:47
@longnt80 events, everyone knows about events
Long Nguyen
@longnt80
Nov 11 2017 13:47
I didn't know about CustomEvent
Adel
@AdelMahjoub
Nov 11 2017 13:48
@longnt80 if you use nodejs, there is the events module
@longnt80 and it is using V8, so it should be something similar on chrome
@longnt80 and it turns out that there is Custom events lol
Long Nguyen
@longnt80
Nov 11 2017 13:48
yeah, I just read about the EventEmitter in Node last week
Adel
@AdelMahjoub
Nov 11 2017 13:53
@longnt80 if used with parsimonie, or in well written modules it is readable and nice, but if written just to work around async calls, then it is even worse than hundreds nested callbacks
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 13:57
anyone who uses bootstrap around?got a question about something that would work
should*
Long Nguyen
@longnt80
Nov 11 2017 13:58
@tiagocorreiaalmeida go ahead, there are many people using bootstrap in here
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 13:58
yeah I dont it myself
but shouldnt when you set font-size to an unity in rems
it resizes later or bootstrap doesnt takes care of that?
Long Nguyen
@longnt80
Nov 11 2017 13:59
not sure I can understand
do you have a use case?
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 14:00
normally we use rems to make everything responsive when I do all the css myself I set the font-size for 62.5% that means 10px that equals 1rem and later I reduce the font-size, I just tought bootstrap would do this for us since they are using rems
cause If I set 1 rem the text ends up almost the same size on the repsonsive version
here an example
image.png
I know how to work around this just tough this was something that would came with bootstrap
lion18
@lion18
Nov 11 2017 14:02
Can I help me what is wrong with this code that the values from api are not being shown in my page? https://codepen.io/lion18/pen/yzrKQw
Long Nguyen
@longnt80
Nov 11 2017 14:02
@tiagocorreiaalmeida you're talking about the heading?
Learn More?
@tiagocorreiaalmeida are you usig bootstrap 4?
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 14:04
yes b4 the point here I set the font-size to 1.2rem but they dont change the font-size on the body in the responsive sizes as they should or maybe im forgetting some setthing
cause imagine a font-size of 2rem = 20px will still be 20px when the screen has 400px if the point was being responsive it would reduce it I would say
Moisés Man
@moigithub
Nov 11 2017 14:06
less than 10px is hard to read
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 14:06
but it wont be less than 10px ;)
maybe im behing confusing nm
if you write the entire website using rems of 1,6 for the default size and bigger for the others
when you go into media queries you just have to change the default size and all the rems will addapt nicely
to the screen
1.6 rem = 10px
16*
letter can be 14px based on the % I give to the body
nm I do it myself just tought this was part of bootstrap
Long Nguyen
@longnt80
Nov 11 2017 14:07
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 14:07
the idea or rems is avoid changing elements
Long Nguyen
@longnt80
Nov 11 2017 14:07
it does resize in my codepen
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 14:07
and I know how it works maybe I was confusing ;)
Long Nguyen
@longnt80
Nov 11 2017 14:08
try to resize the preview window
I only change the html font-size
and the h1 changed accordingly
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 14:08
that wasnt what I was trying to ask
I just asked if bootstrap decide to use rems souldnt it be changing the default font-size on responsive?its a simple behavior
Long Nguyen
@longnt80
Nov 11 2017 14:09
do you know what is rem?
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 14:09
    font-size: 62.5%; /* 16/10=62,5% 62.5% = 1rem */
10px = 1rem*
Long Nguyen
@longnt80
Nov 11 2017 14:09
no
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 14:09
dude xd
ok then
tell me
browser default size = 16px
16/10 = 62,5%
Long Nguyen
@longnt80
Nov 11 2017 14:09
rem make the value relative to the root font size
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 14:09
62.5= 10px
1 rem = 10px
;)
Long Nguyen
@longnt80
Nov 11 2017 14:10
so if I make the root element font-size to 16px
then 1rem = 16px
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 14:10
if I make it 62.5%
it becomes 10px
easier to work with a solid unit
;)
that wasnt my quesiton since the start
but ok
nm I will solve it and thanks @longnt80
CamperBot
@camperbot
Nov 11 2017 14:10
tiagocorreiaalmeida sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
api offline
Long Nguyen
@longnt80
Nov 11 2017 14:11
there's always a fixed root font size
Fabien SHAN
@X140hu4
Nov 11 2017 14:11
@lion18 Using the inspect tool and console.log(); you can poke around your JS to see if you get the values you expect. Your first issue is with your api variable. When you declare it you have no value for lat and lon yet
Stephen James
@sjames1958gm
Nov 11 2017 14:11
@lion18 When you set your api variable lat/lon are unknown - and won't be know until async callback from get position
you have to call $.getJSON from inside of get position callback.
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 14:15
@longnt80 I probably went a bit rude that wasnt my idea, I know how it works normally you write media queries to reduce the root font-size so the entire website addapts the places where you set rems, somehow I tought bootstrap would do that behavior change the root font-size on certain screens size but they dont, that was my question mate, and thanks for trying to help always good to have someone to back you
CamperBot
@camperbot
Nov 11 2017 14:15
tiagocorreiaalmeida sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
api offline
Long Nguyen
@longnt80
Nov 11 2017 14:16
@tiagocorreiaalmeida np man, and no, bootstrap cannot automatically change the font size
lion18
@lion18
Nov 11 2017 14:16
Thanks @camperbot @X140hu4 @sjames1958gm
CamperBot
@camperbot
Nov 11 2017 14:16
lion18 sends brownie points to @camperbot and @x140hu4 and @sjames1958gm :sparkles: :thumbsup: :sparkles:
api offline
api offline
api offline
Moisés Man
@moigithub
Nov 11 2017 14:17
but.. its easier to set the root font-size to 10px instead 62%
(both ways work the same)... font-size: 10px easier to read
Long Nguyen
@longnt80
Nov 11 2017 14:18
@tiagocorreiaalmeida bootstrap uses the default font-size of browsers and that is a fixed font-size
so you still need to use media queries to change the root or default font-size
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 14:20
yeah that was my question, I tought maybe I had something setup wrongly and that bootstrap atually handled that, thanks for pointing it @longnt80
CamperBot
@camperbot
Nov 11 2017 14:20
tiagocorreiaalmeida sends brownie points to @longnt80 :sparkles: :thumbsup: :sparkles:
api offline
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 14:20
camperbot doesnt want to give you some brownies
:D
Long Nguyen
@longnt80
Nov 11 2017 14:21
@tiagocorreiaalmeida :+1:
yeah the bot is sick lately
mstellaluna
@mstellaluna
Nov 11 2017 14:21
@tiagocorreiaalmeida FCC site is currently down. camperbot depends on the FCC db to work.
CamperBot
@camperbot
Nov 11 2017 14:26
roniquericketts sends brownie points to @x140hu4 and @sjames1958gm :sparkles: :thumbsup: :sparkles:
api offline
api offline
Jasper
@Jasperaine
Nov 11 2017 14:48

hello please could somebody help me im trying to convert this code: <a class="next" onclick="plusSlides(1)">&#10095;</a>

function plusSlides(n) {
showSlides(slideIndex += n);
}

into this code$("#plusSlides").click(function plusSlides() {
showSlides(slideIndex = n+1);
});

<a class="prev" id="plusSlides">&#10094;</a>

but its not working
Adel
@AdelMahjoub
Nov 11 2017 15:21
@Jasperaine
  HTMLElement.prototype.on = addEventListener;
  HTMLElement.prototype.off = removeEventListener;

  var slideIndex = 0;
  var slides = 10 // length of your slides array
  var next = getNode('.next');
  var previous = getNode('.prev');

  /**
   * Check if the css selector is valid
   * @param {string} selector
   * @return {void}
   */
  function checkSelector(selector) {
    if(((typeof selector !== 'string') && !(selector instanceof String)) || selector === '') {
      throw new Error(`\`${typeof selector}\`: \`${selector}\` is not a valid css selector`);
    }
  }

  /**
   * Get a reference to a dom node from a css selector
   * @param {string} selector
   * @return {HTMLElement}
   */
  function getNode(selector) {
    checkSelector(selector);
    return document.querySelector(selector);
  }

  next.on('click', function(e) {
    slideIndex = slideIndex === slides ? 0 : slideIndex + 1;
    showSlides(slideIndex);
  });

  previous.on('click', function(e) {
    slideIndex = slideIndex === 0 ? slides : slideIndex -1;
    showSlides(slideIndex);
  });
Khalid Powell
@KhalidPowell
Nov 11 2017 18:51
Can you change a character in a string by it character code?
My apologies, can you create a new string by changing the character codes from another string?
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 18:52
you can
Khalid Powell
@KhalidPowell
Nov 11 2017 18:53
Is it as simple as a loop through the original string and adding or subtracting from the original strings character code and then setting that to the new string?
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 18:54
getting a bit confused can I see what you are trying to create or what exercise you are doing? so I can be more helpfull?
Khalid Powell
@KhalidPowell
Nov 11 2017 18:55
I'm sorry its the Caeser Cipher exercise
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 18:57
yes you can loop the original string and change the string value by another string charcode you need to first get the current charcode and then use another method to turn it into a letter, but yes its possible
Khalid Powell
@KhalidPowell
Nov 11 2017 18:57
Okay thank you
Christopher Brown
@ChrisBrownie55
Nov 11 2017 19:09
@KhalidPowell try .split(‘’).map( your function to change the characters here )
Vincent Chho
@koalavc
Nov 11 2017 19:51
I have two user prompts that asks for user inputs and it stores it in an array. I would like it to store it as [[userinput] [1], [[userinput2] [2], [userinput3][3]] instead it stores the array as [[userinput, userinput2, userinput3] , [1,2,3]]
//Create a blank array
var userInput = [];
var userInput2 = [];
//initialize i to be 0, i must be less than 3, and it will continue to increment until it hits 3
for (i = 0; i < 3; i++) {
  //it will push the users prompt into the console 3 times
  userInput.push(prompt("What do you want to do this weekened? " + (i + 1)));

  userInput2.push(prompt("How many hours do you think it will take? " + (i + 1)));

  var arr3 = [userInput, userInput2];

}
console.log(arr3);
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 20:21
@koalavc
let arr = [];
arr.push([2,3]);
console.log(arr);
wouldnt something like this be more correct?
a 2d array
with arrays inside each array position has 2 values the first input and the second input
Vincent Chho
@koalavc
Nov 11 2017 20:24
@tiagocorreiaalmeida so in arr.push, that is where i would put in my prompts?
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 20:25
plus your array wont contain the 3 arrays you need with the code you have above if you declare the variable everytime the loop runs it will create it everytime it runs
you could declare the array outside the loop
and 2 more variables maybe, one for input1 and other for input2, and then inside the loop set input1 to the result of the prompt
same for the second
and then arr.push([input1,input2])
there was other ways of doing this tough
DistinctWolf
@DistinctWolf
Nov 11 2017 20:30
How can i swap letters for example abc to acb, so basically switching b with c
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 20:30
do you only need to change in 3 letters words or bigger?
DistinctWolf
@DistinctWolf
Nov 11 2017 20:35
more letters
length doesn't matter i just need a way to swap two letters without changing other letters in a string
Christopher Brown
@ChrisBrownie55
Nov 11 2017 20:36
@FlashHero
let str = 'abc', first = 1, second = 2, tmp
str = str.split('')
tmp = str[first]
str[first] = str[second]
str[second] = tmp
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 20:36
that letters have always the same potion?
Christopher Brown
@ChrisBrownie55
Nov 11 2017 20:36
For more letters try using str.substring
DistinctWolf
@DistinctWolf
Nov 11 2017 20:37
@ChrisBrownie55 what does substring do I forgot lol
Christopher Brown
@ChrisBrownie55
Nov 11 2017 20:37
Substring gets a section of a string
DistinctWolf
@DistinctWolf
Nov 11 2017 20:39
can't i do that with slice too , what's the difference
Christopher Brown
@ChrisBrownie55
Nov 11 2017 20:40
You're right, didn't think of that
Use slice
DistinctWolf
@DistinctWolf
Nov 11 2017 20:41
so basically i need to slice out a letter and with the letter i want to replace and use the replace function
@ChrisBrownie55 @moigithub @tiagocorreiaalmeida thanks
CamperBot
@camperbot
Nov 11 2017 20:42
flashhero sends brownie points to @chrisbrownie55 and @moigithub and @tiagocorreiaalmeida :sparkles: :thumbsup: :sparkles:
:cookie: 437 | @tiagocorreiaalmeida |http://www.freecodecamp.com/tiagocorreiaalmeida
:star2: 3705 | @moigithub |http://www.freecodecamp.com/moigithub
:cookie: 269 | @chrisbrownie55 |http://www.freecodecamp.com/chrisbrownie55
Moisés Man
@moigithub
Nov 11 2017 20:46
replace function only changes the first occurrence
ie:
"hello".replace("l","x") --> "hexlo"
soo if u wanna change the 2nd "l" ...... u need to find/use something else
DistinctWolf
@DistinctWolf
Nov 11 2017 20:52
@moigithub is this consistent
var letter='abc';
var second=letter.substring(1,2);
var first=letter.substring(0,1);
letter.replace(second,first).replace(first,second);
Christopher Brown
@ChrisBrownie55
Nov 11 2017 21:09
@FlashHero to switch 'b' and 'c' second = letter.substring(2,3) and first = letter.substring(1,2)
Although I think this way might be slower than just using a temporary variable, not sure but I'd bet that there's more going on behind the scenes of .replace
elpatron17
@elpatron17
Nov 11 2017 21:44
hello guys
could someone help me please
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 21:44
hey
sure
elpatron17
@elpatron17
Nov 11 2017 21:46

<!DOCTYPE html>

<html>
<head>
<title>Browser Emulation</title>
<style>
table, td {
border: 1px solid black;
}
th, td {
padding: 70px 70px;
}
</style>
<script>
var backStackArr = [];
var displayStackArr = [];
var forwardStackArr = [];


function forward() {
document.getElementById("forwardOutput").value =
document.getElementById("userInput").value;
}
function currentInput() {
var s = document.getElementById("userInput").value;
document.getElementById("displayStack").innerHTML = s;
}
</script>
</head>
<body>
<form>
<table>
<tr>
<td style="text-align: center">
<button type="button"> back </button>
</td>
<td style="text-align: center">
URL: <input type="text" name="url" id="userInput" value="H">
<button onclick="currentInput()"> go </button>
</td>
<td style="text-align: center">
<button onclick="forward()"> forward </button>
</td>
</tr>
<tr>
<td style="text-align: center">
<p> Back Store </p>
<textarea rows="10" cols="20">
</textarea>
</td>
<td style="text-align: center" type="text">
<p style="color: red; font-family:verdana; font-size:150px;" id="displayStack">H</p>
</td>
<td style="text-align: center">
<p> Forward Store </p>
<textarea rows="10" cols="20" id="forwardOutput" type="text" >
</textarea>
</td>
</tr>
</table>
</form>
</body>
</html>

so thats my code
I don't know how to fill the arrays from user input and display them on the output
Ive tried few ways but without any success
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 21:48
place this in a codepen and send a link @elpatron17
DistinctWolf
@DistinctWolf
Nov 11 2017 21:49
has anyone done no repeats please algorithm using heap's algorithm
Ken Haduch
@khaduch
Nov 11 2017 21:51
@FlashHero - I had it running at one point, but it seems that I've lost that particular challenge, probably because I never submitted it, I had some cleanup to do on the code.... but I did have it doing at one point!
DistinctWolf
@DistinctWolf
Nov 11 2017 21:53
@khaduch can you explain what i and n stands for in this Wikipedia page please I've been struggling in this challenge for weeks https://en.wikipedia.org/wiki/Heap%27s_algorithm
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 21:54
@elpatron17 so what's the idea here ?
I got an input and 3 buttons
what's the porpuse of the arrays aswell?
elpatron17
@elpatron17
Nov 11 2017 21:55
so
when the user input some url and click on forward button it should stack on the forward store
and replace the H
Ken Haduch
@khaduch
Nov 11 2017 21:56
@FlashHero - n is the number of objects that you have, so it would be the count of the items in the array. i is just a counter that you use within the loop to count how many times you have looped.
elpatron17
@elpatron17
Nov 11 2017 21:56
bellow the url
and when back button is pressed it should have back the previous store
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 21:57
you got the arrays but you are not using them?
DistinctWolf
@DistinctWolf
Nov 11 2017 21:57
@khaduch ohh ok thanks finally I understood, I was just confused since that code is not written in javascript
CamperBot
@camperbot
Nov 11 2017 21:57
flashhero sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3495 | @khaduch |http://www.freecodecamp.com/khaduch
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 21:57
you dont push values to them and you are not getting values from them
elpatron17
@elpatron17
Nov 11 2017 21:58
when the user enter value
it`s just appear for 1second
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 22:01
like I said where are you pushing the values for the array?
elpatron17
@elpatron17
Nov 11 2017 22:03
I just delete that
part
because it did't work
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 22:04
well it wont work without it
when you do go you have to store the current value in the array
when you do back you have to move back 1 position in the array
when you do forward you have to move 1 position up in the array
if its the last do nothing
elpatron17
@elpatron17
Nov 11 2017 22:05
yes
that's the idea
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 22:05
save the values in the arrays then
elpatron17
@elpatron17
Nov 11 2017 22:05
but I stuck and don't know how do it
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 22:06
and you only need 1 array for this
elpatron17
@elpatron17
Nov 11 2017 22:06
should I use linked list?
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 22:07
linked list?
an array is all you need
elpatron17
@elpatron17
Nov 11 2017 22:08
thank you!
"
@tiagocorreiaalmeida
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 22:08
function currentInput() {
  values.push(document.getElementById("userInput").value);
  console.log(values);
}
and only the var values = [];
try this look at your console llog
will give you some ideas how to work next
elpatron17
@elpatron17
Nov 11 2017 22:10
on codepen?
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 22:11
yeah
elpatron17
@elpatron17
Nov 11 2017 22:11
cheers man @tiagocorreiaalmeida
how many function do I need 3?
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 22:12
for the rest of the code you only need to know how to move in array
one to push values , one to go back in the values and one to go forward
so 3 as you have
elpatron17
@elpatron17
Nov 11 2017 22:14
okay
I will try :D
Thank you very much!
Tiago Correia
@tiagocorreiaalmeida
Nov 11 2017 22:14
image you have this array
arr["a","b","c","d"];
how would you get the letter c
you will need to save a variable to know at wich position you are on the array
Donnie
@Donnie-D
Nov 11 2017 23:33
hi all
Jim7894
@Jim7894
Nov 11 2017 23:38
hi
I want the button text to be bold after I have clicked on it
so it will know which coler is lightning
it is a website that teach you coler in English. For an example you press button "red" then the background will turn into red. I want the text red and other coler names to be bold when I'm useing its coler when I have clicked. So you know which text belongs to the coler
Jim7894
@Jim7894
Nov 11 2017 23:43
I have a JS code

var redButton = document.getElementById("red");
var blueButton = document.getElementById("blue");
var greenButton = document.getElementById("green");
var yellowButton = document.getElementById("yellow");
var orangeButton = document.getElementById("orange");
var brownButton = document.getElementById("brown");
var blackButton = document.getElementById("black");
var grayButton = document.getElementById("gray");
var whiteButton = document.getElementById("white");
var pinkButton = document.getElementById("pink");

redButton.addEventListener("click", red);
blueButton.addEventListener("click", blue);
greenButton.addEventListener("click", green);
yellowButton.addEventListener("click", yellow);
orangeButton.addEventListener("click", orange);
brownButton.addEventListener("click", brown);
blackButton.addEventListener("click", black);
grayButton.addEventListener("click", gray);
whiteButton.addEventListener("click", white);
pinkButton.addEventListener("click", pink);
purpleButton.addEventListener("click", purple);

function red() {
document.body.style.backgroundColor="red";
}

function blue() {
document.body.style.backgroundColor="blue";
}

function green() {
document.body.style.backgroundColor="green";
}

function yellow() {
document.body.style.backgroundColor="yellow";
}

function orange() {
document.body.style.backgroundColor="orange";
}

function brown() {
document.body.style.backgroundColor="brown";
}

function black() {
document.body.style.backgroundColor="black";
}

function gray() {
document.body.style.backgroundColor="gray";
}

function white() {
document.body.style.backgroundColor="white";
}

function pink() {
document.body.style.backgroundColor="pink";
}

function purple() {
document.body.style.backgroundColor="purple";
}

should I link the html code too?
Donnie
@Donnie-D
Nov 11 2017 23:54

fellas! Please help me sort this counfusion

(function sr() {
    document.getElementById("demo").innerHTML = "Hello! I called myself";
})();

is a self invoking function only because it has left parenthesis '(' and and right parenthesis ')' around it. otherwise it would be a declaration that can't be self invoked. (Is my explanation correct? if not then please straighten my confusion out on this first. if i am right then comes the next part)

<!DOCTYPE html>
<html>
<body>

<p>Counting with a local variable.</p>

<button type="button" onclick="myFunction()">Count!</button>

<p id="demo">0</p>

<script>
(function add() {
    var counter = 0;
    return function () {return counter += 1;}
})();

function myFunction(){
    document.getElementById("demo").innerHTML = add();
}
</script>

</body>
</html>

in this above code, why does the function add not self invoke itself?

alpox
@alpox
Nov 11 2017 23:58
@Donnie-D it does invoke itself. But it only defines a variable which is captured in local scope and returns a function which is never used or called
And you add a function to the innerHTML with your = add();