These are chat archives for FreeCodeCamp/HelpJavaScript

27th
Nov 2017
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 00:02
jesus I was looking at this for ours
hours
a return stop a function
hope you know it :D
somehow I wasnt even looking at it
FlashHero
@FlashHero
Nov 27 2017 00:04
The return in if statement ?
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 00:04
yeah
and there's more issues
but that's one of them
with that return the line below will never run
FlashHero
@FlashHero
Nov 27 2017 00:05
Ok let me check
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 00:05
you will need to move out this
    var stop;
    var track = 'current_time';
    var count = parseInt($('#show').text() * 60);
        function counter() {
        var minutes = (count / 60);
        var seconds = count % 60;

        if (Math.floor(minutes) == 0 && seconds == 0) {
            if (track !== 'current_break') {
                count = parseInt($('#break-count').text() * 60);
                track = 'current_break';
            } else {
                count = parseInt($('#time-count').text() * 60);
                track = 'current_time';
            }
        } else if (minutes < 10 && seconds < 10) {
            $('#show').text('0' + Math.floor(minutes) + ' : ' + '0' + Math.floor(seconds));
            count--;
        } else if (seconds < 10) {
            $('#show').text(Math.floor(minutes) + ' : ' + '0' + Math.floor(seconds));
            count--;
        } else if (minutes < 10) {
            $('#show').text('0' + Math.floor(minutes) + ' : ' + Math.floor(seconds));
            count--;
        } else {
            $('#show').text(Math.floor(minutes) + ' : ' + Math.floor(seconds));
            count--;
        }
}
out of your click handler
you allready have something below that call's the function when its needed
place that code before the click handler
and its solved
I didnt liked when people gave me the solution itself but sadly I need ot go sleep here its an working pen with what I told you about if you dont make it work check the pen
FlashHero
@FlashHero
Nov 27 2017 00:09
@tiagocorreiaalmeida oh finally it worked thanks man
CamperBot
@camperbot
Nov 27 2017 00:09
flashhero sends brownie points to @tiagocorreiaalmeida :sparkles: :thumbsup: :sparkles:
:cookie: 454 | @tiagocorreiaalmeida |http://www.freecodecamp.org/tiagocorreiaalmeida
Stephen James
@sjames1958gm
Nov 27 2017 00:48
@FlashHero Move your var stop; to the top of the function it might be a hoisting problem.
nvm looks like you solved it
tahashin
@tahashinegp
Nov 27 2017 07:57
var Url="https://fcc-weather-api.glitch.me/api/current?lon="$longitude +"&lat="$latitude"; is this ok? for weather app
actual code is:

var longitude;
var lattitude;
$(document).ready(function(){
getlocaltion();
var Url="https://fcc-weather-api.glitch.me/api/current?lon="$longitude +"&lat="$latitude";
$.ajax({
type: 'GET',
uri: 'Url'

});

});

function getlocaltion(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(function(position) {
longitude= position.coords.longitude;
lattitude=position.coords.latitude;
$('#weather').html("longitue :" +longitude+"lattitude :" +lattitude)
});
}
}

Markus Kiili
@Masd925
Nov 27 2017 08:17
@tahashinegp Those global variables don't get values when getlocation() is executed. They get values at some point later when the geolocation response comes.
tahashin
@tahashinegp
Nov 27 2017 08:18
hmmm. I have to return from getlocation()
?
Markus Kiili
@Masd925
Nov 27 2017 08:19
If you need to use the geolocation response when you make the ajax call, you need to make the ajax call inside the geolocation callback function (or call a function from the re that does the same).
Only inside the geolocation callback you know that the response has come.
tahashin
@tahashinegp
Nov 27 2017 08:20
nice thanks for you valuable reply
Markus Kiili
@Masd925
Nov 27 2017 08:20
Your code structure needs to be changed so you take into account the async nature of those ajax calls.
tahashin
@tahashinegp
Nov 27 2017 08:22
so what shouold I do? could you please me suggest me the best way.
Markus Kiili
@Masd925
Nov 27 2017 08:23
@tahashinegp Make the $.ajax call inside the geolocation callback function function(position) {...}
tahashin
@tahashinegp
Nov 27 2017 08:24
ohh okk
Markus Kiili
@Masd925
Nov 27 2017 08:25
@tahashinegp When the geolocation response comes at some point later (after the script has finished), the engine automatically executes that callback function and passes the response into that callback. Therefore you should use the response inside that callback and make the second ajax call there.
So using global variables is not helping here. Changing the structure does.
tahashin
@tahashinegp
Nov 27 2017 08:27
hmm. let's try
Thanks
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 08:42
gm everyone
https://tiagocorreia-pinterestclone.glitch.me if you guys can give it a look, and maybe spot why mansory isnt work,ing properly soem times
Adel
@AdelMahjoub
Nov 27 2017 09:19
@tiagocorreiaalmeida it works correctly, that means you completed the backend challenges, good job
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 09:23
if you refresh it multiple times the mansory thing will sometimescover the post above and others work, correctly
uits strange :D
trying to spot the issue since yesterday
Adel
@AdelMahjoub
Nov 27 2017 09:30
yeah noticed that, some cards overlap, I could help you but never used masonryjs, but it it is not that bad, you could leave it like that
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 09:31
btw thanks @AdelMahjoub ,kthe only bad thing is that sometimescover part of the text but yeah probably some issue with bs4 cause it previousversion doesnt seems to be therea ny issue
CamperBot
@camperbot
Nov 27 2017 09:31
tiagocorreiaalmeida sends brownie points to @adelmahjoub :sparkles: :thumbsup: :sparkles:
:cookie: 629 | @adelmahjoub |http://www.freecodecamp.org/adelmahjoub
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 09:31
any
Ankur sharma
@ankur1163
Nov 27 2017 09:38
how can i make checkbox and paragraph text on same line
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 09:42
paragrtaph by default havea display:block that forces a line break plusif you areusing inputs a label is what you need and using a label it will allready stay on same line
if you really wanna use a paragraph and that's not recomend, you need display inline-block or display flex
label's gives you the possiblity of clicking the text to check the box when using id's
Ankur sharma
@ankur1163
Nov 27 2017 09:50
@tiagocorreiaalmeida
i dont want it checked
when someone click text
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 09:50
then remove the id's
Ankur sharma
@ankur1163
Nov 27 2017 09:51
ok
but how do i put in same line?
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 09:51
here
for inputs you should use labels liekI said
Ankur sharma
@ankur1163
Nov 27 2017 09:53
it worked
thanks @tiagocorreiaalmeida
CamperBot
@camperbot
Nov 27 2017 09:53
ankur1163 sends brownie points to @tiagocorreiaalmeida :sparkles: :thumbsup: :sparkles:
:cookie: 455 | @tiagocorreiaalmeida |http://www.freecodecamp.org/tiagocorreiaalmeida
Ankur sharma
@ankur1163
Nov 27 2017 09:53
so if we use label isntead of
<p>
it gets into same line?
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 09:53
thedefault style for a p tag has a display of block
block elements take the entire row for themself
Ankur sharma
@ankur1163
Nov 27 2017 09:54
ok
cool
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 09:54
display block works like a line break
Claudio Restifo
@Marmiz
Nov 27 2017 09:55
hi peeps, someone here's familiar with Apollo GraphQL?
Ankur sharma
@ankur1163
Nov 27 2017 10:04
@Marmiz check discord
there is channel there
Farooq Abdul Rehman
@FarooqAR
Nov 27 2017 10:11

Hello folks! Can someone tell me how to generate a pattern like this?
for n=2:

2
212
21012
212
2

number of lines are determined by let's say i = n*2+1

Blauelf
@Blauelf
Nov 27 2017 10:23
Some coding exercise?
Two nested loops would do. Could be any kind of loops, even map with join, or something like that.
Farooq Abdul Rehman
@FarooqAR
Nov 27 2017 10:24
yeah i know that
but that info is not enough
Blauelf
@Blauelf
Nov 27 2017 10:25
You know how to count? There are countless ways to do that :D
Farooq Abdul Rehman
@FarooqAR
Nov 27 2017 10:25
to be more specific, I wanna know how to get each term in each line
I tried many ways without any luck
Blauelf
@Blauelf
Nov 27 2017 10:35

A simple way would be to have two loops, and add to a string, like

var output = "";
for (var row = -n; row <= n; row++) {
    for (var column = Math.abs(row)-n; column <= n-Math.abs(row); column++) {
        output += Math.abs(column)+Math.abs(row);
    }
    output += "\n";
}

Here row and column refer to indices relative to an imaginary center at the zero, assuming the lines were centered horizontally.

The number then is the sum of the absolute values of those indices.
Farooq Abdul Rehman
@FarooqAR
Nov 27 2017 10:37
thanks bro! you are my saviour!
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 13:49
anyone around who has used passport-local?
Tugaaa
@Tugaaa
Nov 27 2017 14:24
// Setup
var myArray = [];

// Only change code below this line.
while(i <= 4){
  var i = 0;
  myArray.push(i);
  i++;
}
Hey, I can't understand why in this code I can't use a local variable ? The only one who's supposed to be global is myArray variable, no ?
Alexander Køpke
@alexanderkopke
Nov 27 2017 14:27
while(i <=4) where is i defined first?
Tugaaa
@Tugaaa
Nov 27 2017 14:28
can't i define it inside the loop ?
oh guess i got it then, when the loop starts, the code doesnt have any "i" variable, so the loop can not start, is that correct?
So, i need to declare it before and outside the loop?
Alexander Køpke
@alexanderkopke
Nov 27 2017 14:31
I think i doesn't exist when the while starts. So probably it needs to be declare outside the while for the while to use it
as it is now var i = 0; will set i to 0. Eventhough you add one to it later on it will always be push as 0 to myArray
Markus Kiili
@Masd925
Nov 27 2017 14:33
@Tugaaa That var i declares a global variable.
Alexander Køpke
@alexanderkopke
Nov 27 2017 14:33
but if you make var i = 0; outside the while then the while will work as expected
Tugaaa
@Tugaaa
Nov 27 2017 14:34
got it ! ty
Alexander Køpke
@alexanderkopke
Nov 27 2017 14:34
awesome
Tugaaa
@Tugaaa
Nov 27 2017 14:34
and @Masd925 ye my bad, guess local variables are only inside functions :pp
Markus Kiili
@Masd925
Nov 27 2017 14:34
@Tugaaa Yes, code blocks matter only if you use let or const instead of var.
Tugaaa
@Tugaaa
Nov 27 2017 14:35
oh okay ! thanks
Ghost
@ghost~59cdefc7d73408ce4f77dab0
Nov 27 2017 15:20
What should I use for if suppose I want to animate my button such that on hover my glyphicon slides left to right
Christopher McCormack
@cmccormack
Nov 27 2017 15:57
@parthprakash1 you can use transform: translate(10px, 10px); for example. translate(tx, ty) is the syntax, and ty isn't required
Blauelf
@Blauelf
Nov 27 2017 16:17
Also, :hover pseudo class for the selector
JeremyWeisener
@JeremyWeisener
Nov 27 2017 16:27
Hi, I'm having trouble figuring out where my syntax error is in my code. It's throwing Syntax Error: expected expression, got '<'
this is the source to the code
Codepen
it's throwing on Line 7 at the opening bracket for the <td key={key}> </td>
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 16:30
hey @cmccormack
Christopher McCormack
@cmccormack
Nov 27 2017 16:32
@tiagocorreiaalmeida heya :)
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 16:33
how are you? have you fell asleep while watching the last 2 weeks of mongodb course? :D
Christopher McCormack
@cmccormack
Nov 27 2017 16:33
@tiagocorreiaalmeida last week was pretty rough, yeah haha
@JeremyWeisener I don't believe you can map over your array until you add values - when you do Array(50) or whatever the pointers in each slot are undefined.
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 16:35
how's nodejs going?
Christopher McCormack
@cmccormack
Nov 27 2017 16:35
@JeremyWeisener
> Array(50)
[ <50 empty items> ]
> Array(50).map((v,i)=>i)
[ <50 empty items> ]
> Array(50).fill(0).map((v,i)=>i)
[ 0,
  1,
  2,
  3,
  4,
  5,
...
JeremyWeisener
@JeremyWeisener
Nov 27 2017 16:35
I knew they would be undefined but didn't know it would affect mapping, I'll go try to fix that now, thank you very much @cmccormack !
CamperBot
@camperbot
Nov 27 2017 16:35
jeremyweisener sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1275 | @cmccormack |http://www.freecodecamp.org/cmccormack
Christopher McCormack
@cmccormack
Nov 27 2017 16:36
@tiagocorreiaalmeida going ok haven't done much so far, been busy with some home renovation and the Thanksgiving holiday. Got back into it yesterday working on some passport local auth stuff
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 16:37
voting app?
Christopher McCormack
@cmccormack
Nov 27 2017 16:37
@tiagocorreiaalmeida yeah. I also made an app for work to access data on an SDN management device and push the results of the aggregate data to a log file, fairly simple but some good experience
I'm still having a little trouble trying to determine how to handle errors. Like if I can't connect to the mongodb server at some point, should the user just get an error, or should they only get an error when trying to log in or handle data from the db
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 16:40
by errors you mean database connection errors or queries errors?
are you using mongodb nativero mongosoe?
native
Christopher McCormack
@cmccormack
Nov 27 2017 16:40
I'm going to play with Mongoose this time
more like database access errors, like what if the credentials are changed while the server is running or mlab is temporarily unavailable or whatever
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 16:46
I guess some middleware that would check if the database is running everytime and if something goes wrong redirect them or send them a json message
I atually never handled it myself but was doing some search
Christopher McCormack
@cmccormack
Nov 27 2017 16:47
I probably won't try to handle that for this project but was curious how a professional site would handle it
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 16:48
// test.js
require('./app.js'); // which executes 'mongoose.connect()'

var mongoose = require('mongoose');
console.log(mongoose.connection.readyState);
found on stack overflow
seems that this returns 4 values
Output - 0 = disconnected, 1 = connected, 2 = connecting,3 =disconnecting
not sure if when fails it returns the 0 but something I will try right now :D
Christopher McCormack
@cmccormack
Nov 27 2017 16:51
haha yeah just test it why not
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 16:55
@cmccormack changed thedb url for somerandom text it returns 0
Christopher McCormack
@cmccormack
Nov 27 2017 16:55
so you can use that variable anytime you need to call the database then determine how to notify the user if there is a db issue I guess
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 16:56
app.use((req,res,next)=>{
  if(mongoose.connection.readyState === 0){
    res.send("Server down");
  }else{
    next();
  }
});
how about this?
check before run any route
if there's no issuecall next and it goes on
Christopher McCormack
@cmccormack
Nov 27 2017 16:59
I think something like that would work. If I use it I'll probably add it to the post routes I'm adding, as I'm using React Router for all other routes
karinafarina
@karinafarina
Nov 27 2017 17:00
Hi, what am I doing wrong here?
function caseInSwitch(val) {
  var answer = "";
  // Only change code below this line
  switch(val) {
    case 1:
        answer == "alpha";
        break;
    case 2:
        answer == "beta";
        break;
    case 3:
        answer == "gamma";
        break;
    case 4:
        answer == "delda";
        break;

  }


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

// Change this value to test
caseInSwitch(1);
Christopher McCormack
@cmccormack
Nov 27 2017 17:00
@karinafarina put three backticks around your code ``` in gitter so it parses it correctly
on their own line
Blauelf
@Blauelf
Nov 27 2017 17:02
@karinafarina Those are == abstract equal, not = assign as they should
Christopher McCormack
@cmccormack
Nov 27 2017 17:02
delta is not spelled correctly either
FlashHero
@FlashHero
Nov 27 2017 17:02
@karinafarina change == to = the double equal checks if they're equal
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 17:02
@cmccormack uh im thinking about starting react :D
karinafarina
@karinafarina
Nov 27 2017 17:03
That fixed it! thanks guys!!
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 17:05
@cmccormack you can aswell make a function of it andcall it only in the routes you need
like app.post("/path",middleware,((req,res
Christopher McCormack
@cmccormack
Nov 27 2017 17:05
@tiagocorreiaalmeida you should start react! very interesting, although getting it to work with Node was a head scratcher at first
@tiagocorreiaalmeida yeah that was the plan, i'll have to play with that a bit
not quite there yet
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 17:07
or something like this
router.use('/test', function(req, res, next) {
  // write your callback code here.
  next();
});
this one atually didnt tough of
yeah I think im gonnapick an udemy course forreact
Christopher McCormack
@cmccormack
Nov 27 2017 17:11
I have the Modern React with Redux course on Udemy, havent started though
I found the best resource was the Facebook documentation
at least so far
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 17:13
I took the nodejs course from andrew and was the jump I needed for nodejs that's why im checking this one aswell, I have no iodeaatually how this works at all, but some people told me to learn vuejs aswell
Christopher McCormack
@cmccormack
Nov 27 2017 17:14
I'd like to try vue as well. However, at my work, they are heavily investing in React so I'm trying to stick with it for now
React isn't actually all that complicated, but it's kind of a shift in how you think of writing apps
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 17:15
how do you use react with node? you make api requests or something like that?
Christopher McCormack
@cmccormack
Nov 27 2017 17:15
yeah
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 17:15
so all the backend job its about create an api ?
Christopher McCormack
@cmccormack
Nov 27 2017 17:15
that's how I plan to do it, that's why I'll only have a few routes, mostly post
I'll serve the index file that loads react from a default path
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 17:16
thanks if possible
can you show me like how you make the requests?
to make me get lost :D
Christopher McCormack
@cmccormack
Nov 27 2017 17:16
haven't got that far, but I was just planning on using fetch or axios
oh wait I did
I made a login request, one sec
been a long holiday weekend :)
ah yeah I didn't even have to use an api call, just used the post action in my form
<form id='login_form' action='/login'method='post'>
Routes look like this so far and it's working ok:
  app.get('/api_test', (req, res) => {
    res.type('json').send(JSON.stringify(
      {
        'result': 'success'
      }
    ))
  })

  app.post('/login', (req, res) => {
    res.type('json').send(JSON.stringify(
      {
        'username': req.body.username,
        'password': req.body.password
      }
    ))
  })

  // Handle invalid routes that React Router cannot
  app.get('/:path/*', (req, res) => {
    console.log(`New Request for ${req.hostname + req.path}`)
    res.redirect('/')
  })

  // Default route loads React app
  app.get('*', (req, res) => {
    console.log(`New Request for ${req.hostname + req.path}`)
    res.sendFile(path.join(static, 'index.html'))
  })
not complete, just testing stuff so far
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 17:19
oh ok that's what I do normally , less the last get
Christopher McCormack
@cmccormack
Nov 27 2017 17:19
index.html links the script bundle.js which contains all my react and js code
All the rest of my routes are within my react router
      <Switch>
        <Route exact path="/login" component={Login} />
        <Route exact path="/main" component={Main} />
        <Route exact path="/" component={Main} />
        <Route render={(props) => (
          <h1>404 Page not found</h1>
        )}/>
      </Switch>
hoping I don't need much more logic to get the rest of it working :D
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 17:22
looksa bit confusing, what the component does? :D a call?
Christopher McCormack
@cmccormack
Nov 27 2017 17:22
component tells react router which component to render based on the path
Switch is supposed to only match the first path found, otherwise you could end up rendering multiple components if there are multiple matches
I'm not great with React Router yet, the documentation wasn't great for v4 when I started working with it. Might be better now
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 17:24
uh ok, will give it a try this week for sure, gonna try to rebuild my entire portfolio aswell, but web design is the kind of thing that leads people into suicide I think
Christopher McCormack
@cmccormack
Nov 27 2017 17:25
@tiagocorreiaalmeida haha!
I have made multiple attempts at starting my portfolio over again but I feel like it's one of those projects that doesn't feel as fulfilling to work on, considering how much other fun stuff there is to do
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 17:27
I got a portfolio with a 7mb img on top good old days
the website opens and the image starts to open slowly
piece by piece
maybe its not 7 I probably cahgned but still's a big sized file for sure
Christopher McCormack
@cmccormack
Nov 27 2017 17:40
@tiagocorreiaalmeida why not make it smaller?
@tiagocorreiaalmeida I haven't read this yet but maybe check it out as well - https://medium.freecodecamp.org/using-svg-as-placeholders-more-image-loading-techniques-bed1b810ab2c
Tiago Correia
@tiagocorreiaalmeida
Nov 27 2017 18:14
I know some tricks now plus aspect rqtiovand stufd but back then didnt even know those things existed :smile:
Christopher Brown
@ChrisBrownie55
Nov 27 2017 18:37

Hey, I need some help with my code for the Smallest Common Multiple challenge, I'm getting this error

Internal Error: too much recursion
from this code:
```
// jshint esversion: 6

function missingNumbers( low, high ) {
let ret = []
while ( low <= high )
ret.push( low++ )
return ret
}

function GCM( a, b ) {
if ( a === b )
return a
else if ( a > b )
return GCM( a - b, b )
else
return GCM( a, b - a )
}

function LCM( a, b ) {
return ( a * b ) / GCM( a, b )
}

function smallestCommons(arr) {
arr = missingNumbers( Math.min( ...arr ), Math.max( ...arr ) ).reverse()
return arr.reduce( ( t, x ) => t / x % 1 !== 0 ? LCM( t, x ) : t )
}

smallestCommons([23,18]);
```

// jshint esversion: 6

function missingNumbers( low, high ) {
  let ret = []
  while ( low <= high )
    ret.push( low++ )
  return ret
}

function GCM( a, b ) {
  if ( a === b )
    return a
  else if ( a > b )
    return GCM( a - b, b )
  else
    return GCM( a, b - a )
}

function LCM( a, b ) {
  return ( a * b ) / GCM( a, b )
}

function smallestCommons(arr) {
  arr = missingNumbers( Math.min( ...arr ), Math.max( ...arr ) ).reverse()
  return arr.reduce( ( t, x ) => t / x % 1 !== 0 ? LCM( t, x ) : t )
}


smallestCommons([23,18]);
Stephen James
@sjames1958gm
Nov 27 2017 18:47
@ChrisBrownie55 Your GCM must never reach a === b
@ChrisBrownie55 I ran your code with console.log in LCM function and
2018940 18
these were the two numbers after 5 passes
Stephen James
@sjames1958gm
Nov 27 2017 18:53
You might need a different algorithm for GCM using recursion
function gcd(a, b)
    if b = 0
       return a; 
    else
       return gcd(b, a mod b);
Christopher Brown
@ChrisBrownie55
Nov 27 2017 19:23
@sjames1958gm Thank you that fixed it, however it was working before, it did reach a === b; however it just took too long.
CamperBot
@camperbot
Nov 27 2017 19:23
chrisbrownie55 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8717 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Stephen James
@sjames1958gm
Nov 27 2017 19:30
@ChrisBrownie55 Ah. That is what I was thinking.
karinafarina
@karinafarina
Nov 27 2017 19:31
Can I get some help understanding what I'm doing wrong here?
https://beta.freecodecamp.org/en/challenges/basic-javascript/counting-cards
var count = 0;

function cc(card) {
  // Only change code below this line

  switch(card) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
     count = count+1;
      return count;
    case 7:
    case 8:
    case 9:
      count = count;
      return count;
    case 10:
    case 'J':
    case 'Q':
    case 'K':
    case 'A':
      count = count-1;
      return count;
  }
    if(count >= 1){
      return "Bet";
    } else {
      return "Hold";
    }

  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
Stephen James
@sjames1958gm
Nov 27 2017 19:34
@karinafarina Your returns in the switch are wrong and stopping you from getting to the if / else
Your returns at the bottom should include the count
karinafarina
@karinafarina
Nov 27 2017 19:41
Not sure what you mean.
var count = 0;

function cc(card) {
  // Only change code below this line

  switch(card) {
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
     count = count+1;
     break;
    case 7:
    case 8:
    case 9:
      count = count;
      break;
    case 10:
    case 'J':
    case 'Q':
    case 'K':
    case 'A':
      count = count-1;
  }
    if(count >= 1){
      return "Bet";
    } else {
      return "Hold";
    }

  // Only change code above this line
}

// Add/remove calls to test your function.
// Note: Only the last will display
cc(2); cc(3); cc(7); cc('K'); cc('A');
@sjames1958gm so this? but what did you mean by the last part?
Your returns at the bottom should include the count
Kaz Baig
@kbaig
Nov 27 2017 19:49
@karinafarina with the above code, you're still only returning the strings 'Bet' or 'Hold'
He means you're also supposed to return the count, right?
But you're not currently doing that
Christopher McCormack
@cmccormack
Nov 27 2017 19:55

@karinafarina - @kbaig is correct, your return should include the current count, something like return count + " Hold";

The function will then return a string with the current count and the string "Bet" if the count is positive, or "Hold" if the count is zero or negative. The current count and the player's decision ("Bet" or "Hold") should be separated by a single space.

Stephen James
@sjames1958gm
Nov 27 2017 20:01
@karinafarina What those guys said :) ^^
karinafarina
@karinafarina
Nov 27 2017 20:24
Thanks againguys!!
anothr one
// Setup
var testObj = {
  12: "Namath",
  16: "Montana",
  19: "Unitas"
};

// Only change code below this line;

var playerNumber= "Montana";       // Change this Line
var player = testOjb[playerNumber];   // Change this Line
Stephen James
@sjames1958gm
Nov 27 2017 20:26
@karinafarina is "Montana" a number?
@karinafarina Also watch for typos like testOjb
karinafarina
@karinafarina
Nov 27 2017 20:39

// Setup
var testObj = {
  12: "Namath",
  16: "Montana",
  19: "Unitas"
};

// Only change code below this line;

var playerNumber= testObj[16];       // Change this Line
var player = playerNumber;   // Change this Line
I still don't know
I don't get why I don't understand
Bryan Reese
@breese8009
Nov 27 2017 20:41
@karinafarina im assuming it wants player number
both playerNumber and player are the same, giving u the value
not the key
i beleive u want the key
but i donno what challenge that is
@karinafarina whats the name of this challenge?
Christopher McCormack
@cmccormack
Nov 27 2017 20:43

The instructions kind of stink here:

Use the playerNumber variable to look up player 16 in testObj using bracket notation. Then assign that name to the player variable.

Bryan Reese
@breese8009
Nov 27 2017 20:44
lol
Christopher McCormack
@cmccormack
Nov 27 2017 20:44
@karinafarina try simply assigning the number (in this case 16) to playerNumber (it is called playerNumber, after all...) and do the object lookup during the player assignment (var player = testObj[...])
Bryan Reese
@breese8009
Nov 27 2017 20:44
whats the name of the challenge?
i found it
nvm
ty
oh yea
Christopher McCormack
@cmccormack
Nov 27 2017 20:47
@karinafarina if you feel like you're not understanding, make it a point to read the exercise a few times, and look at the test expectations at the bottom. They can really help you understand what the problem is looking for
Bryan Reese
@breese8009
Nov 27 2017 20:48
hes got the right idea, just the instructions are bad lol
how did i lose these challenges?
not that i care
but my solutons are gone
solutions
Christopher McCormack
@cmccormack
Nov 27 2017 20:50
It's the beta
Stephen James
@sjames1958gm
Nov 27 2017 20:50
@karinafarina The variable playerNumber - should be assigned a number - the name is a hint.
Bryan Reese
@breese8009
Nov 27 2017 20:51
wow fcc just wouldnt let me pass cause semi colon
ughhhh
dont need em
Christopher McCormack
@cmccormack
Nov 27 2017 20:51
add this at the top @breese8009 : // jshint esversion:6, asi:true
I don't use them either so I just paste that in
Bryan Reese
@breese8009
Nov 27 2017 20:52
where? top of the challenge?
Christopher McCormack
@cmccormack
Nov 27 2017 20:52
yeah
Bryan Reese
@breese8009
Nov 27 2017 20:52
i did an it didnt work?
Christopher McCormack
@cmccormack
Nov 27 2017 20:52
/shrug
Bryan Reese
@breese8009
Nov 27 2017 20:52
still wants semi colon :(
lol
Christopher McCormack
@cmccormack
Nov 27 2017 20:52
FCC challenges can be buggy too, If I actually want to submit a new answer, I have to reset the problem and reload the page and then add the code
Bryan Reese
@breese8009
Nov 27 2017 20:52
ill try that
nope
lol
fcc trippin
Christopher McCormack
@cmccormack
Nov 27 2017 20:53
It's really weird because I can change the code and hit submit and it will still pass even if the code is bogus
hmm maybe they changed it, I finished all the exercises a while ago
Bryan Reese
@breese8009
Nov 27 2017 20:54
im having to do all these
some i never seen
Christopher McCormack
@cmccormack
Nov 27 2017 20:54
on the beta?
Bryan Reese
@breese8009
Nov 27 2017 21:00
yea
i never really looked at beta
well no not beta
like thats a new challenge
i never seen
Christopher McCormack
@cmccormack
Nov 27 2017 21:02
did you do them last year? I show that one completed in Jan 2017, maybe you just missed it :D
Lucky you, more to do!
Bryan Reese
@breese8009
Nov 27 2017 21:02
i completed it jan 17?
2017*
Christopher McCormack
@cmccormack
Nov 27 2017 21:03
You asking me?
Bryan Reese
@breese8009
Nov 27 2017 21:03
i donno lol
who were u saying completed in jan 2017?
u?
Christopher McCormack
@cmccormack
Nov 27 2017 21:04
Yes I completed it in Jan 2017 so it's been around at least that long
Bryan Reese
@breese8009
Nov 27 2017 21:04
oh lol i havent done anychallenges on here in a long time

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

  // Only change code below this line
  var lookup = {
    "alpha":"Adams",
    "bravo":"Boston",
    "charlie":"Chicago",
    "delta": "Denver",
    "echo": "Easy",
    "foxtrot": "Frank"
  };


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

// Change this value to test
phoneticLookup("charlie");
Christopher McCormack
@cmccormack
Nov 27 2017 21:47
@karinafarina you're returning result but didn't assign anything but the empty string to it
Consider how you should use the value (val) passed to your function to return the proper result, stored in the variable result
karinafarina
@karinafarina
Nov 27 2017 21:50
I don't know
Christopher McCormack
@cmccormack
Nov 27 2017 21:51
in your example above, you are calling your function with the argument "charlie"
karinafarina
@karinafarina
Nov 27 2017 21:51
yes and I want the result to be Chicago
Christopher McCormack
@cmccormack
Nov 27 2017 21:51
So within your function, "charlie" is stored in the first function parameter variable val, so within the function you can use val to represent "charlie"
after you create your lookup object, which looks good from what I see so far, you then have to actually get the value stored at the property "charlie", which is stored in the variable val
Do you remember how to do a lookup using a variable?
karinafarina
@karinafarina
Nov 27 2017 21:57
This exersise is teaching that but I don't understand

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

  // Only change code below this line
  var lookup = {
    "alpha":"Adams",
    "bravo":"Boston",
    "charlie":"Chicago",
    "delta": "Denver",
    "echo": "Easy",
    "foxtrot": "Frank"
  };
  lookup[val];

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

// Change this value to test
phoneticLookup("charlie");
Christopher McCormack
@cmccormack
Nov 27 2017 21:57
actually a previous exercise taught that
it's not even that far up where you posted a use of it
karinafarina
@karinafarina
Nov 27 2017 21:57
oh I looked but didn't see it
Christopher McCormack
@cmccormack
Nov 27 2017 21:57
right! bracket notation will do a lookup using a variable
however, you're doing a lookup but not doing anything with the result of it
@karinafarina because you can't modify the last statement in your function, how would you go about storing the result of your lookup in the returned variable result?
karinafarina
@karinafarina
Nov 27 2017 22:01
I don't know, this is so hard
Christopher McCormack
@cmccormack
Nov 27 2017 22:02
how do you store any value in a variable?
karinafarina
@karinafarina
Nov 27 2017 22:02
you just put the value after the =
Christopher McCormack
@cmccormack
Nov 27 2017 22:02
If you're finding it difficult, you may want to go back to the first javascript exercise and re-read the instructions as well as examine the working code to really make sure you understand
@karinafarina right, = is used for assignment. So lookup[val] will give you a result, but you need to store that result in result using the assignment operator, how would you do that?
karinafarina
@karinafarina
Nov 27 2017 22:07

var result = lookup[val];

This did not work

Christopher McCormack
@cmccormack
Nov 27 2017 22:08
don't declare your variable twice
show me your current code
karinafarina
@karinafarina
Nov 27 2017 22:08
// Setup
function phoneticLookup(val) {
  var result = lookup[val];

  // Only change code below this line
  var lookup = {
    "alpha":"Adams",
    "bravo":"Boston",
    "charlie":"Chicago",
    "delta": "Denver",
    "echo": "Easy",
    "foxtrot": "Frank"
  };


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

// Change this value to test
phoneticLookup("charlie");
Christopher McCormack
@cmccormack
Nov 27 2017 22:09
You need to read the comments, don't change code above or below the lines
The mistake you made above is you assigned the lookup result before you even created the lookup variable
karinafarina
@karinafarina
Nov 27 2017 22:11
Ok, I got it to pass, thank you @cmccormack
CamperBot
@camperbot
Nov 27 2017 22:11
karinafarina sends brownie points to @cmccormack :sparkles: :thumbsup: :sparkles:
:star2: 1276 | @cmccormack |http://www.freecodecamp.org/cmccormack
Christopher McCormack
@cmccormack
Nov 27 2017 22:11
@karinafarina :thumbsup:
Bryan Reese
@breese8009
Nov 27 2017 22:40
@cmccormack u there?
Christopher McCormack
@cmccormack
Nov 27 2017 22:40
yes
Bryan Reese
@breese8009
Nov 27 2017 22:40
hey what is Ramdajs used for?
like specifically
Christopher McCormack
@cmccormack
Nov 27 2017 22:41
looks like it's for writing functional javascript
Portmanteau of Ram and Lambda I guess
I've not learned too much about functional programming though, just bits and pieces
Bryan Reese
@breese8009
Nov 27 2017 22:44
ive always heard of it
never got into it
Christopher McCormack
@cmccormack
Nov 27 2017 22:46
I think the idea is to never mutate state, always return something new from any function call
like how map returns a new array
React is actually pretty good at maneuvering us closer to functional programming I think
Probably unintentionally but still welcome
Bryan Reese
@breese8009
Nov 27 2017 22:48
so its a bunch of higher order functions
Christopher McCormack
@cmccormack
Nov 27 2017 22:50
hmm some are, the ones I was looking at didn't appear to be but I can check again
Bryan Reese
@breese8009
Nov 27 2017 22:51
pre built functions
Christopher McCormack
@cmccormack
Nov 27 2017 22:53
yeah, doesn't look all that different from lodash but I've only looked at it briefly
but I don't think lodash always returns a different result without modifying the input, maybe that's the main difference
gotta run for a bit see ya