23rd
Jan 2018
johnny mayer
@johnnymayer
Jan 23 2018 07:41
howdy y'all: i need help creating an array from 0 to X, where X is a number inputted by a user

//user interface logic
\$("form#userNumber").submit(function(event) {
event.preventDefault();
var inputtedUserNumber = \$("input#userNumberInput").val();
});
});

anyone
HELLOOOOOOOO
BUELLER
BUELLER
BUELER?!
Markus Kiili
@Masd925
Jan 23 2018 07:53
@johnnymayer First figure out a way to store the board state. Have you done that?
bahaa aldin
@bahaa-al-deen
Jan 23 2018 08:38

hey everyone
i'm trying to implement binary search using JS but i'm having a weird problem

``````function binary_search(array, required) {
let middle = Math.floor((array.length - 1) / 2);
if (array[middle] == required) {
return middle;
}
else if (array[middle] > required) {
binary_search(array.slice(0, middle), required);
}
else if (array[middle] < required) {
binary_search(array.slice(middle+1), required);
}
else if (array.length == 1 && array[0] != required) {
return -1;
}
}``````

when i call `binary_search([ 1, 5, 8, 12, 13 ], 1)` it outputs `undefined`

Markus Kiili
@Masd925
Jan 23 2018 08:45
@bahaa-al-deen If you just call `binary_search(...)` recursively, the function doesn't make a return and returns `undefined` by default. Maybe you mean `return binary_search(...);` ?
bahaa aldin
@bahaa-al-deen
Jan 23 2018 08:51
@Masd925 yes, you're right
@Masd925 thanks alot
CamperBot
@camperbot
Jan 23 2018 08:51
bahaa-al-deen sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4666 | @masd925 |http://www.freecodecamp.org/masd925
Slomon80
@Slomon80
Jan 23 2018 09:17
hi
anybody in the room?
Simon Cordova
@gbsimon87
Jan 23 2018 09:27

Good morning!
Was wondering if anybody had any idea how to implement a snap scroll effect on a banner?
ex: https://bet.coral.co.uk/#/ (in mobile view)

As you can see, the banner images are scrollable and 'snap' to the div

yofri
Jan 23 2018 13:55
Hi guys, whats wrong with my fetch code.
I'm trying to get some image
``````fetch(`http://www.clashapi.xyz/images/arenas/\${this.props.arena.idName}.png`)
.then(res => res.blob())
.then(myBlob => {
const arenaImage = URL.createObjectURL(myBlob)
this.setState({arenaImage})
})
.catch(err => console.error(err))``````
I also provide init parameter, but still no works
Pieter Stokkink
@forkerino
Jan 23 2018 13:57
@Yofri What does the console tell you?
yofri
Jan 23 2018 13:58
@forkerino if I console the `arenaImage` it shows link like this `blob:http://localhost:3000/99f48cd5-7242-4f27-9bd2-8e0cbe24de33` when I click it does not an image
Pieter Stokkink
@forkerino
Jan 23 2018 14:07
@Yofri and what happens if you log the first response (`res`)?
yofri
Jan 23 2018 14:11
@forkerino wait I want yo show you the image, but imgur took forever to load
@forkerino here the screenshot of the response https://photos.app.goo.gl/bK4aDyVrxl4gBmhn1
yofri
Jan 23 2018 14:18
if I log the second `then` it only shows size & mimetype, but no image buffer like with base64 prefix
Pieter Stokkink
@forkerino
Jan 23 2018 14:40
I'm not entirely sure how to do this
Chris
@ConnectCodes
Jan 23 2018 14:40

Hi guys doing “Inventory Update” challenge: “Compare and update the inventory stored in a 2D array against a second 2D array of a fresh delivery. Update the current existing inventory item quantities (in arr1). If an item cannot be found, add the new item and quantity into the inventory array. The returned inventory array should be in alphabetical order by item.”

But I dont get anything on console.

First I used `map()` to interate `arr1`if item exists `val[1] === arr2[i][1]` I add quantities`val[0] += arr2[i][0]` and update `arr1` then removed it from `arr2.splice(i,1)`to avoid duplication. If item doesn’t exists `push()` it to arr1. Because its a 2d array used for loop to compare the item names. I dont get any results, nothing shows up in console a bit confused. Did I use for loop/map corretly?
https://codepen.io/Codeconnect/pen/qpQQrZ?editors=0012

Pieter Stokkink
@forkerino
Jan 23 2018 14:45
@ConnectCodes codepen's console is incomplete, if you open your browser's console you'll see the error: `Uncaught TypeError: Cannot read property '1' of undefined`
probably because splice changes the length of the array
I would not use a for loop inside a .map, that is very hard to reason about
Chris
@ConnectCodes
Jan 23 2018 14:51
@forkerino yes it was splice, now I get array with `undefined`. Reason I used for loop there was to access and compare 2d arrays. For example to `"Bowling Ball”`
Not sure how else I can do that. Unless I ditch `map` and just use for loop?
Pieter Stokkink
@forkerino
Jan 23 2018 14:52
@Yofri maybe it is because they don't allow Cross Site fetching of the image?
yofri
Jan 23 2018 14:53
@forkerino I think I'm dumb, Its a link refer to image, I just need to use it to my element. thanks for helping me anyway
CamperBot
@camperbot
Jan 23 2018 14:53
yofri sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2971 | @forkerino |http://www.freecodecamp.org/forkerino
Pieter Stokkink
@forkerino
Jan 23 2018 14:56
@ConnectCodes I thought a bit more, I don't think you'll make it work with a .map, because how will you add the items that are in the second one, but not in the first one? You cannot really do that with .map. I think it is better to combine everything, maybe sort them somehow and then use a .reduce or some other loop to aggregate the duplicate items (with the same name)
Chris
@ConnectCodes
Jan 23 2018 15:07
@forkerino Makes sense I will try that. Thank you !
CamperBot
@camperbot
Jan 23 2018 15:07
connectcodes sends brownie points to @forkerino :sparkles: :thumbsup: :sparkles:
:star2: 2972 | @forkerino |http://www.freecodecamp.org/forkerino
dinesh
@1532j0004kg
Jan 23 2018 15:42
``````C:\Users\dinesh\Desktop\Project folder\meetup>node server
express-session deprecated undefined resave option; provide resave option server
.js:14:9
express-session deprecated undefined saveUninitialized option; provide saveUnini
tialized option server.js:14:9
server is listening on port 8000``````
deprecated means?
Kaz Baig
@kbaig
Jan 23 2018 15:42
No longer supported in favor of something else, so you gotta go look for an updated version or something
dinesh
@1532j0004kg
Jan 23 2018 15:42
and why it displaying ?
what i want to do ?
to repair this err .
Kaz Baig
@kbaig
Jan 23 2018 15:45
You'll prob find the answer in the package's docs
dinesh
@1532j0004kg
Jan 23 2018 15:45
ok
@kbaig thanks
CamperBot
@camperbot
Jan 23 2018 15:45
1532j0004kg sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
Blauelf
@Blauelf
Jan 23 2018 15:47
@1532j0004kg Others seem to have same problem, is probably related to package configuration: expressjs/session#438
dinesh
@1532j0004kg
Jan 23 2018 15:49
@Blauelf thanks
CamperBot
@camperbot
Jan 23 2018 15:49
1532j0004kg sends brownie points to @blauelf :sparkles: :thumbsup: :sparkles:
:star2: 4676 | @blauelf |http://www.freecodecamp.org/blauelf
dinesh
@1532j0004kg
Jan 23 2018 16:24
``````var express = require("express");
var mongoose = require("mongoose");
var router = express.Router();

var postSchema = mongoose.Schema({
companyname : String,
meetingplace : String,
});

var postModel = mongoose.model("data" , postSchema);

router.post('/postdata' , function(req , res){
sess = req.session

{
var newData = new postModel();
newData.companyname = req.body.companyname;
newData.meetingplace = req.body.meetingplace;
newData.save(function(err , savedObject){
res.send(savedObject);
});

}
else{
console.log("error posting");
}
});

router.get('/fetchdata' , function(req , res){

postModel.find({} , function(err , foundObject){
res.send(foundObject);
});

});

router.get("/logout" , function(req,res){
req.session.destroy(function(err){
if(err)
{
console.log("err destroying");
}
else {

}
});
});

module.exports = router ;``````
in this i didn't create the session or require("express-session")
``````var express = require("express");
var router = express.Router();
var mongoose = require('mongoose');
var session = require("express-session");
var sess;

});

sess = req.session;

newUser.save(function(err,savedObject){
if(err)
{
res.statusCode(500).send();
}
else {
res.send(savedObject);
}
});
});

module.exports = router;``````
in this file only i created or require the session .
but still its worked how ?
can u please explain guys .
Thankyou :sparkles:
This message was deleted
dinesh
@1532j0004kg
Jan 23 2018 16:40
my question how is carrying the session into the file (wich did not containing the `reqire('express-session')`?
Jason Luboff
@JLuboff
Jan 23 2018 16:44
Are you sure the first one worked? Had you stopped and started the server (or are you using nodemon)?
dinesh
@1532j0004kg
Jan 23 2018 16:44
no i didn't use the nodemon
1st one worked , without requiring the express-session
Jason Luboff
@JLuboff
Jan 23 2018 16:47
Ok...had you stopped and restarted the service when you had removed it?
dinesh
@1532j0004kg
Jan 23 2018 16:48
do u mean session removed?
Jason Luboff
@JLuboff
Jan 23 2018 16:48
Yes.
dinesh
@1532j0004kg
Jan 23 2018 16:48
when i clicking on the logout .
``````router.get("/logout" , function(req,res){
req.session.destroy(function(err){
if(err)
{
console.log("err destroying");
}
else {

}
});
});``````
this part is doing that job .!
Jason Luboff
@JLuboff
Jan 23 2018 16:50
What? Everytime you make a change to your files you need to stop and restart the server. Otherwise changes made won't be reflected until the next time you stop and start the server
dinesh
@1532j0004kg
Jan 23 2018 16:50
yes i am doing like that only :smile:
my question ==> how is carrying the session(wich is created in another file) into the file (wich did not containing the reqire('express-session')?
is it possible ?
Jason Luboff
@JLuboff
Jan 23 2018 16:52
If that worked, then I'm not sure.
dinesh
@1532j0004kg
Jan 23 2018 16:53
but by the term and condition it must not work ?
Jason Luboff
@JLuboff
Jan 23 2018 16:54
I wouldn't think it would
dinesh
@1532j0004kg
Jan 23 2018 16:54
but its worked here :smile:
Mr. Frosty
@BinaryKing
Jan 23 2018 17:03

function truncateString(str, num) {
// Clear out that junk in your trunk
if(str.length<=num){
return str
}else if(str.length<3){ return str.slice(0, num)+"..." }else if(str.length+3>num){
return str.slice(0, num-3)+"..."
}

}
truncateString("Absolutely Longer", 2)

Tiago Correia
@tiagocorreiaalmeida
Jan 23 2018 17:18
@1532j0004kg can I see the main file where you group all the routes?
dinesh
@1532j0004kg
Jan 23 2018 17:18
sure @tiagocorreiaalmeida
``````var express = require("express");
var bodyParser = require("body-parser");
var mongoose = require("mongoose");
var session = require("express-session");
var postModel = require('./models/postdata.js');

mongoose.connect('mongodb://localhost/meetup');
mongoose.Promise = global.Promise;

var app = express();
app.use(express.static('front'));
app.use(express.static('post'));
app.use(session({secret:"secret" ,  resave: true,
saveUninitialized: true}));
app.use(bodyParser.json());
app.use(usersModel);
app.use(postModel);

app.listen('8000',function(){
console.log("server is listening on port 8000");
});``````
Tiago Correia
@tiagocorreiaalmeida
Jan 23 2018 17:19
you are forcing the entire app to use the session package
that's why it works on the others routes
or atleast I think so
dinesh
@1532j0004kg
Jan 23 2018 17:21
is it okay , to do this ?
but here its working good !
Jason Luboff
@JLuboff
Jan 23 2018 17:24
@1532j0004kg ...you didn't mention you had express-session in your main file.. thats why it works..
dinesh
@1532j0004kg
Jan 23 2018 17:26
where i want to mention ?
@JLuboff
Jason Luboff
@JLuboff
Jan 23 2018 17:28
dinesh
@1532j0004kg
Jan 23 2018 17:28
so can u pls say where i want to mention ?
Stephen James
@sjames1958gm
Jan 23 2018 17:30
@BinaryKing You are supposed to compare num to 3 not str.length
Jason Luboff
@JLuboff
Jan 23 2018 17:31
@1532j0004kg You only need express-session in your main file if thats what you're asking.
Mr. Frosty
@BinaryKing
Jan 23 2018 17:32
@sjames1958gm That was it, thank you so much
CamperBot
@camperbot
Jan 23 2018 17:32
binaryking sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8885 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
dinesh
@1532j0004kg
Jan 23 2018 17:32
thanks @JLuboff
CamperBot
@camperbot
Jan 23 2018 17:32
1532j0004kg sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
:star2: 2304 | @jluboff |http://www.freecodecamp.org/jluboff
Stephen James
@sjames1958gm
Jan 23 2018 17:32
@BinaryKing :+1:
dinesh
@1532j0004kg
Jan 23 2018 17:32
@JLuboff i can't able to get ur words ,sry?
can u pls tell in another way ?
Jason Luboff
@JLuboff
Jan 23 2018 17:33
I'm not sure how else to word it. Maybe somebody else can
dinesh
@1532j0004kg
Jan 23 2018 17:34
Thanks for ur help @JLuboff :+1:
CamperBot
@camperbot
Jan 23 2018 17:34
1532j0004kg sends brownie points to @jluboff :sparkles: :thumbsup: :sparkles:
api offline
jusgoose
@gusd773
Jan 23 2018 18:30

help ? "where do I belong" challenge

/*
function getIndexToIns(arr, num) {
var indexTracker = 0;
var sortArr = arguments[0].sort();
for (var i = 0; i<sortArr.length; i++){ if (num>sortArr[i]){
indexTracker = indexTracker+1;
}
else {
return;
}
}
}
return indexTracker;
}

getIndexToIns([40, 60], 50); */

Kaz Baig
@kbaig
Jan 23 2018 18:31
Jan 23 2018 18:47
@gusd773
``````function getIndexToIns(arr, num) {
var indexTracker = 0;
var sortArr = arguments[0].sort();
for (var i = 0; i < sortArr.length; i++) {
if (num > sortArr[i]) {
indexTracker = indexTracker + 1;
} else {
return;
}
}
}
return indexTracker;
}
getIndexToIns([40, 60], 50);``````
theres a problem right there...
Looks like there are 1 to many brackets
jusgoose
@gusd773
Jan 23 2018 18:49
@bradtaniguchi true still not working tho :(
I feel like this should work
Jan 23 2018 18:50
@gusd773 whats the challenge again so we know the goal? can you provide a link to it so we can all read the prompt?
jusgoose
@gusd773
Jan 23 2018 18:50
@bradtaniguchi "where do I belong" challenge
Jan 23 2018 18:50
ok.. Ill look it up myself
the first return breaks you out of the loop and returns from the function, which is the main reason why its not working
Kaz Baig
@kbaig
Jan 23 2018 18:53
this is all happening outside of the function
``````return indexTracker;
}``````
Jan 23 2018 18:53
You can do 1 of two things, 1 return the indexTracker in the first return, OR use break
IsmailHusseinCR
@IsmailHusseinCR
Jan 23 2018 20:15
Guys im trying to learn a bit more about scoping
why is b 2 here
``````var a = 1;
var b = 2;
var c = 3;

function changeMeOne(b){
var a = 10;
a = a + b;
return a;
}

function changeMeTwo(c){
c = 2;
b = c;
return c;
}

b = changeMeOne(b);
c = changeMeTwo(c);

console.log(a);
console.log(b);
console.log(c);``````
Kaz Baig
@kbaig
Jan 23 2018 20:17
@IsmailHusseinCR it isn't. It should be 12 here
IsmailHusseinCR
@IsmailHusseinCR
Jan 23 2018 20:17
but the 3 console logs down
show 1 2 2
Kaz Baig
@kbaig
Jan 23 2018 20:17
Not for me
Oh wait I'm being stupid and didn't read better lol
``````function changeMeTwo(c){
c = 2;
b = c;
return c;
}``````
every time you call `changeMeTwo`, you're assigning `b` a value of 2
`b` was 12 right before calling it
Sorry long day at work so far haha
IsmailHusseinCR
@IsmailHusseinCR
Jan 23 2018 20:20
hehehe ye its some kinda javascript scoping exercise from school
but its so fishy
Kaz Baig
@kbaig
Jan 23 2018 20:20
It's not really unintuitive, I'm just tired af :D
IsmailHusseinCR
@IsmailHusseinCR
Jan 23 2018 20:21
i didnt even notice that the b = c
so the 12 turned into 2
Kaz Baig
@kbaig
Jan 23 2018 20:21
You got it
IsmailHusseinCR
@IsmailHusseinCR
Jan 23 2018 20:21
so the value of A that logs 1
Kaz Baig
@kbaig
Jan 23 2018 20:22
makes sense
IsmailHusseinCR
@IsmailHusseinCR
Jan 23 2018 20:22
the function changeMeOne does nothing with it
Kaz Baig
@kbaig
Jan 23 2018 20:22
`changeMeOne` does not mutate any of the three global variables
IsmailHusseinCR
@IsmailHusseinCR
Jan 23 2018 20:22
because it has is own var a
Kaz Baig
@kbaig
Jan 23 2018 20:22
and `changeMeTwo` mutates the global `b` and `c`
IsmailHusseinCR
@IsmailHusseinCR
Jan 23 2018 20:24
hmm
Kaz Baig
@kbaig
Jan 23 2018 20:24
When you call `b = changeMeOne(b);` you're assigning `b` the result of `changeMeOne(2)`
So it becomes 12
IsmailHusseinCR
@IsmailHusseinCR
Jan 23 2018 20:25
the changeMeOne function does not affect the global a
Kaz Baig
@kbaig
Jan 23 2018 20:25
When you call `c = changeMeTwo(c);`, `b` becomes 2 and `c` becomes 2 because the function call `changeMeTwo(c);` returns 2
IsmailHusseinCR
@IsmailHusseinCR
Jan 23 2018 20:25
why
Kaz Baig
@kbaig
Jan 23 2018 20:25
because it defines its own internal variable, which also happens to be called `a`
After that `var a` declaration, all references to `a` are to the one in the function scope
IsmailHusseinCR
@IsmailHusseinCR
Jan 23 2018 20:26
so the return is only that a on his own scope which has the value of 12
Kaz Baig
@kbaig
Jan 23 2018 20:26
Actually, because of hoisting, even references to `a` in the function `changeMeOne` above the `var a` declaration would refer to the local variable `a`
I think...
IsmailHusseinCR
@IsmailHusseinCR
Jan 23 2018 20:27
ahh
so the a is 1 down there because we had no a = changeMeOne()
so it got the global var value
Kaz Baig
@kbaig
Jan 23 2018 20:28
Pretty much
IsmailHusseinCR
@IsmailHusseinCR
Jan 23 2018 20:29
ahh
really stinky exercise
got tricked
really prefer the notation of functionName(2) instead of functionName(b)
anyways thanks @kbaig
CamperBot
@camperbot
Jan 23 2018 20:30
ismailhusseincr sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
Kaz Baig
@kbaig
Jan 23 2018 20:31
@IsmailHusseinCR no problem. You're basically referring to the concept of pure vs impure functions here
Hendrik W.
@sol-idsnake
Jan 23 2018 21:08
do some of you know react well ?
Christopher McCormack
@cmccormack
Jan 23 2018 21:08
@sol-idsnake some people do
Hendrik W.
@sol-idsnake
Jan 23 2018 21:08
do you ?
Christopher McCormack
@cmccormack
Jan 23 2018 21:09
I know enough to make things show up on the screen but no means an expert
Jason Luboff
@JLuboff
Jan 23 2018 21:09
:joy:
Hendrik W.
@sol-idsnake
Jan 23 2018 21:10
@cmccormack i am trying to see the difference between npm install react etc., and create-react-app... they produce similar files on the disk, except that create-react-app puts a looot more files on. why is that
Christopher McCormack
@cmccormack
Jan 23 2018 21:11
create-react-app is basically a boilerplate for starting a react app - it includes lots of other modules like webpack and babel to make the process of actually writing your react code much easier
Hendrik W.
@sol-idsnake
Jan 23 2018 21:13
if i had known that i wouldn't have followed the codecademy tutorial where they install all those separately
Christopher McCormack
@cmccormack
Jan 23 2018 21:13
setting up your environment for React can take quite a bit of work so create-react-app is to help make things easier.
There isn't just one way to do it
Hendrik W.
@sol-idsnake
Jan 23 2018 21:14
i guess create-react-app comes with a basic config ?
if not i guess the other way is not really that much longer
Christopher McCormack
@cmccormack
Jan 23 2018 21:16
create-react-app is a suite of different tools that work together to make building a react app easier. Building it yourself will require building configs for webpack, babel, linters, dev-tools, etc... or their equivalents which actually does take quite a bit longer if you really want to understand how they work
Hendrik W.
@sol-idsnake
Jan 23 2018 21:17
i don't lol. i followed codecademy's tutorial for creating a basic hello world screen but nothing happens. each tutorial shows me difference imports and exports to include. it's quite frustrating
Christopher McCormack
@cmccormack
Jan 23 2018 21:18
ok
Hendrik W.
@sol-idsnake
Jan 23 2018 21:19
do you know of a straight forward tutorial to make this happen ?
Christopher McCormack
@cmccormack
Jan 23 2018 21:21
hmm you can search for something like `react babel webpack setup` and there are lots of blog posts
setting up the environ and actually using React are quite different
I enjoyed the youtube channel ihatetomatoes, between his react and webpack playlists there's lots of useful info, but I would also recommend learning what each of these tools actually does, how it's configured, and how it all works together. It's pretty daunting to set it up yourself and can take a while to fully comprehend.
Just for learning React I recommend the facebook documentation
Hendrik W.
@sol-idsnake
Jan 23 2018 21:24
sounds good, i've been using `reactjs.org` for the most part
Hendrik W.
@sol-idsnake
Jan 23 2018 21:41
Isaiah Trembley
@IsaiahCT
Jan 23 2018 22:22
hey guys, I am wondering why my obstacle is not showing up. I tested out my function, and it works
it the obstacle just showing up somewhere I can't see it
Stephen James
@sjames1958gm
Jan 23 2018 22:29
@IsaiahCT Are you talking about the rectangle that moves left to right with the mouse? It shows for me, but then stopped moving
Isaiah Trembley
@IsaiahCT
Jan 23 2018 22:32
No not the rectangle
if you look in the js code, there is a fucntion that it suppose to spawn a circle on the screen
but it is not showingup up
Conor Murphy
@cmurphy580
Jan 23 2018 22:32
I have a frequent problem when iterating through an array/object of images using a variable for an index and interval to add to the variable and do the iterating. For the first loop through the array the image or background glitches and then changes the picture. To getter a better idea of what i'm talking about check out the problem here:https://cmurphy580.github.io/eCommerce-Site-_-FjallRaven/
Anyone know how to get rid of that glitch when using an interval and index variable?
Isaiah Trembley
@IsaiahCT
Jan 23 2018 22:33
@sjames1958gm what do you think
I changed the parameters of the x and y, if that helps, but still no chang
Stephen James
@sjames1958gm
Jan 23 2018 22:40
@IsaiahCT not sure, seems like it should show something
Stephen James
@sjames1958gm
Jan 23 2018 22:50
@IsaiahCT I commented out requestAnimationFrame and the circle appeared
Stephen James
@sjames1958gm
Jan 23 2018 23:10
@sjames1958gm Maybe redraw on the mouse move event?
Isaiah Trembley
@IsaiahCT
Jan 23 2018 23:37
@sjames1958gm why do you think that happened
Stephen James
@sjames1958gm
Jan 23 2018 23:38
@IsaiahCT I am thinking that you are calling the function too often and holding up rendering the circle - only a guess
Isaiah Trembley
@IsaiahCT
Jan 23 2018 23:39
@sjames1958gm hm.... akes sense,