These are chat archives for FreeCodeCamp/Help

10th
Feb 2018
Alex
@alexandrupintilei
Feb 10 2018 15:07
Hi, I want to tweet a quote after i press on tweeter icon,this is my attemp:
https://codepen.io/balexoy/pen/gvmobj
Jeremy Cherer
@JavaLavaMT
Feb 10 2018 15:21
@alexandrupintilei so you want to make the twitter bird a button?
Alex
@alexandrupintilei
Feb 10 2018 15:22
i tryed same function on a button, stil dosent work
@JavaLavaMT
Jeremy Cherer
@JavaLavaMT
Feb 10 2018 15:24
@alexandrupintilei try this href="https://twitter.com/intent/tweet/?text="
@alexandrupintilei you may also have to encode it if you have any special charters
Alex
@alexandrupintilei
Feb 10 2018 15:29
@JavaLavaMT i want to User Story: I can press a button to tweet out a quote.
Jeremy Cherer
@JavaLavaMT
Feb 10 2018 15:32
@alexandrupintilei var url = "https://twitter.com/share?text="; replace with var url = "https://twitter.com/intent/tweet/?text="
Alex
@alexandrupintilei
Feb 10 2018 15:33
thats why i did
what*
Jeremy Cherer
@JavaLavaMT
Feb 10 2018 15:36
@alexandrupintilei do you know about jquery? I think if I remember i had to use jquery to get the text from the quote box and then it worked
Alex
@alexandrupintilei
Feb 10 2018 15:39
@JavaLavaMT i know a bit, but i though i can do this with vanilla js
@JavaLavaMT thx
CamperBot
@camperbot
Feb 10 2018 15:39
alexandrupintilei sends brownie points to @javalavamt :sparkles: :thumbsup: :sparkles:
:cookie: 261 | @javalavamt |http://www.freecodecamp.org/javalavamt
Gersho
@Gersho
Feb 10 2018 15:42

@alexandrupintilei do you know about jquery? I think if I remember i had to use jquery to get the text from the quote box and then it worked

you don't need to "get" the text from the box, this text (the quote) was already obtained when you did the API call

Hello :3
Jeremy Cherer
@JavaLavaMT
Feb 10 2018 15:45
@Gersho yeah but its coming across as undefined
Gersho
@Gersho
Feb 10 2018 15:47
what is ?
Aditya
@ezioda004
Feb 10 2018 15:52
@alexandrupintilei .value as far as I remember is used to get value from input, for other elements you need to do .textContent property. So doing var text = document.getElementById("text").textContent; will get you the quote text.
Gersho
@Gersho
Feb 10 2018 15:53
you sure like to make it more complicated than necessary, the quote is already in a JS variable
Alex
@alexandrupintilei
Feb 10 2018 15:54
@ezioda004 thx
Aditya
@ezioda004
Feb 10 2018 15:54
@alexandrupintilei Also remove "?text=" from window.open since you already have that in url.
Alex
@alexandrupintilei
Feb 10 2018 15:56
@ezioda004 dosent work
Aditya
@ezioda004
Feb 10 2018 15:56
@alexandrupintilei What does work? tweet button?
Alex
@alexandrupintilei
Feb 10 2018 15:56
yes
Aditya
@ezioda004
Feb 10 2018 15:57
@alexandrupintilei It works, you need to first click the quote button then tweet button :P
@AmitP88 With a quick look you have the good ol async problem.
Amit Patel
@AmitP88
Feb 10 2018 16:00
@ezioda004 async problem?
@ezioda004 I don't know what you mean
Gersho
@Gersho
Feb 10 2018 16:01
@AmitP88 try toFixed(2) for your lon/lat
Amit Patel
@AmitP88
Feb 10 2018 16:03
@Gersho ok, one sec
Aditya
@ezioda004
Feb 10 2018 16:04
@AmitP88 Nevermind, I was thinking of something else
Amit Patel
@AmitP88
Feb 10 2018 16:04
@Gersho ok, it trimmed the lat and lon decimals down to 2, but I still get the error
@ezioda004 no worries
@Gersho
toFixed.png
Gersho
@Gersho
Feb 10 2018 16:07
i'm comparing to mine but i can't seem to find where's the difference
Amit Patel
@AmitP88
Feb 10 2018 16:09
@Gersho plus, when I click on the link in the console the data shows up just fine in a new tab
Gersho
@Gersho
Feb 10 2018 16:09
      var callUrl = "https://fcc-weather-api.glitch.me/api/current?lat=";
      callUrl += latit;
      callUrl += "&lon=";
      callUrl += longit;

      $.ajax({
        url: callUrl,
        dataType: "json",
        headers: { "Api-User-Agent": "fCC_CodePen_Gersho" },
        type: "GET",

        success: function(data) {
this is mine (it works)
and your call seem to be the same
Stephen James
@sjames1958gm
Feb 10 2018 16:09
@AmitP88 get location is async, so you have to call the $.ajax in the get location callback or the lat/lon wont be set yet
Gersho
@Gersho
Feb 10 2018 16:10
oh it wasn't nested ? i hadn't noticed
Amit Patel
@AmitP88
Feb 10 2018 16:12
@sjames1958gm oh I see. ok, it works now. :)
Stephen James
@sjames1958gm
Feb 10 2018 16:12
@AmitP88 wrap your $.ajax in a function and call that function from your showPosition function passing lat/lon
  function getWeather(lat, lon) {
  $.ajax({
    'url': 'https://fcc-weather-api.glitch.me/api/current?lat=' + lat + '&lon=' + lon,
    'type': 'GET',
    'success': function(data) {
      console.log('https://fcc-weather-api.glitch.me/api/current?lat=' + lat + '&lon=' + lon);
      console.log(data);
    }
  });
  }
Amit Patel
@AmitP88
Feb 10 2018 16:12
@sjames1958gm @Gersho thanks guys :)
CamperBot
@camperbot
Feb 10 2018 16:12
amitp88 sends brownie points to @sjames1958gm and @gersho :sparkles: :thumbsup: :sparkles:
:cookie: 592 | @gersho |http://www.freecodecamp.org/gersho
:star2: 8958 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
Stephen James
@sjames1958gm
Feb 10 2018 16:12
@AmitP88 That is how I would do it, but you can put your ajax call in the showPosition function
Amit Patel
@AmitP88
Feb 10 2018 16:14
@sjames1958gm I was looking at this for the geolocation https://www.w3schools.com/html/html5_geolocation.asp
but it didn't mention anything about it being async. That's probably what threw me off
Stephen James
@sjames1958gm
Feb 10 2018 16:15
@AmitP88 not good on their part
Amit Patel
@AmitP88
Feb 10 2018 16:15
@sjames1958gm but wait, since I have to have my get request nested within the showPosition function, will I still have access to the data variable outside of it?
@sjames1958gm so say I want to make a separate function for showing the local temperature, would I still be able to use the data object?
Stephen James
@sjames1958gm
Feb 10 2018 16:16
You can pass that data from the $.ajax to the callback as parameters.
Amit Patel
@AmitP88
Feb 10 2018 16:17
@sjames1958gm ah ok, so when I make my new function, just pass in the data as the parameter?
Stephen James
@sjames1958gm
Feb 10 2018 16:18
@AmitP88 yes. 90% or higher of your functions should get their data through parameters.
Amit Patel
@AmitP88
Feb 10 2018 16:18
@sjames1958gm I see. ok, i'll try it right now. thanks :)
CamperBot
@camperbot
Feb 10 2018 16:18
amitp88 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
api offline
Stephen James
@sjames1958gm
Feb 10 2018 16:25
@AmitP88 :+1:
Alex
@alexandrupintilei
Feb 10 2018 17:42
Can someone help me and tell me why this code dosent work in my browser(chrome) even is allright? thx
https://codepen.io/balexoy/pen/gvmobj
Gersho
@Gersho
Feb 10 2018 17:48
i don't have chrome but it seems to work on vivaldi and firefox
Alex
@alexandrupintilei
Feb 10 2018 17:51
it dosent work for me ( in chrome )
Alexander Jarman
@HeinousTugboat
Feb 10 2018 18:10
Works for me in Chrome v64.
..63.
:laughing:
..also v64. Just updated. :joy:
Darren
@DarrenfJ
Feb 10 2018 18:14
afternoon fCC
Gersho
@Gersho
Feb 10 2018 18:17
:wave: @DarrenfJ
Darren
@DarrenfJ
Feb 10 2018 18:17
hey buddy
how goes the code?
Kyle Holm
@thekholm80
Feb 10 2018 18:18
@DarrenfJ :wave:
Aditya
@ezioda004
Feb 10 2018 18:19
@DarrenfJ @Gersho @thekholm80 :wave:
Darren
@DarrenfJ
Feb 10 2018 18:19
@thekholm80 hey buddy
Kyle Holm
@thekholm80
Feb 10 2018 18:19
@ezioda004 hiya
Darren
@DarrenfJ
Feb 10 2018 18:19
finally got to the part of the vampire show where they talk about her as being a van helsing
Kyle Holm
@thekholm80
Feb 10 2018 18:20
very cool
I figured you'd be listening to podcasts today
Darren
@DarrenfJ
Feb 10 2018 18:20
i was
last night was Van Helsing
guylozius
@guylozius
Feb 10 2018 18:21
hey, can someone help with my css problem.
Darren
@DarrenfJ
Feb 10 2018 18:21
@guylozius we can try... what is it?
Aditya
@ezioda004
Feb 10 2018 18:21
@DarrenfJ I still like the Hugh Jackman one
Darren
@DarrenfJ
Feb 10 2018 18:22
@ezioda004 yah that one was pretty good too...
Aditya
@ezioda004
Feb 10 2018 18:22
Cheesy at times but still entertaining
Darren
@DarrenfJ
Feb 10 2018 18:22
but this a netflix seres i think
Kyle Holm
@thekholm80
Feb 10 2018 18:22
i think i have a copy of that somewhere, I should watch it again
Gersho
@Gersho
Feb 10 2018 18:22

how goes the code?

slowly

guylozius
@guylozius
Feb 10 2018 18:24
why is my css not being applie to my html flie.
Amit Patel
@AmitP88
Feb 10 2018 18:24

hey guys, I'm nearly done with the Local Weather App, but I'm having trouble getting the F to C converter to work. I made a simple jquery click event for it, but it's not working and I don't know why. Please help :)

https://codepen.io/AmitP88/pen/QQpNKp?editors=1010

Kyle Holm
@thekholm80
Feb 10 2018 18:26
@AmitP88 function(F,C) { where is this anonymous function getting the values of F and C?
if I add console.log(F) into that function I get
image.png
Aditya
@ezioda004
Feb 10 2018 18:28
@AmitP88 Apparently the #temperature div also contains the temperature so you're comparing something like 67 F to F or C
Amit Patel
@AmitP88
Feb 10 2018 18:28
@thekholm80 I defined F and C above the function just outside of it.
Kyle Holm
@thekholm80
Feb 10 2018 18:28
that's not how that works
function (F, C) { is creating new variables called F and C within the scope of that function
Amit Patel
@AmitP88
Feb 10 2018 18:29
I tried it at first without passing in F, C in the click event function, but it still didn't work
Gersho
@Gersho
Feb 10 2018 18:30
you shouldn't need both, you have the one you get from your api call, so you only need to calculate the other one
Kyle Holm
@thekholm80
Feb 10 2018 18:30
if i remove the (F, C) from that function, the value of F becomes 38 &#8457
sorry, i was logging C
Amit Patel
@AmitP88
Feb 10 2018 18:32
@Gersho oh, the one in the api is in celsius, and I wanted to make the one in my app defaulted to fahrenheit, so I just made those two variables to make it easier to switch from one to another
ok, I sort of got it to work
Darren
@DarrenfJ
Feb 10 2018 18:33
ok...off for :tea: and podcasts
Kyle Holm
@thekholm80
Feb 10 2018 18:33
@DarrenfJ have fun my friend
Amit Patel
@AmitP88
Feb 10 2018 18:34

https://codepen.io/AmitP88/pen/QQpNKp?editors=1010

ok, I may need to make this into a switch case. When I first load the app (when the temp is F), I can click on it to turn to C, but after that, if I click on C, it won't change back

guylozius
@guylozius
Feb 10 2018 18:35
my css not being applied to my html flie.
Kyle Holm
@thekholm80
Feb 10 2018 18:35
@guylozius we need to see code to have a prayer of helping
guylozius
@guylozius
Feb 10 2018 18:36

<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
<title>test run</title>
<link href="new 1.css" rel="stylesheet" type="test/css"/>
</head>
<body>
<h1>test run </h1>
</body>
</html>

h1{
background-color: blue;
}
Kyle Holm
@thekholm80
Feb 10 2018 18:36
is your css and html files in the same directory?
guylozius
@guylozius
Feb 10 2018 18:36
yes
Kyle Holm
@thekholm80
Feb 10 2018 18:37
and your css file is named new 1.css?
guylozius
@guylozius
Feb 10 2018 18:37
yes
Kyle Holm
@thekholm80
Feb 10 2018 18:38
i've never used a space in a file name before, not sure if that would cause issues?
Gersho
@Gersho
Feb 10 2018 18:38
space should be %20 iirc ?
Kyle Holm
@thekholm80
Feb 10 2018 18:39
perhaps that's all it is
guylozius
@guylozius
Feb 10 2018 18:39
ok i wil change and see
Gersho
@Gersho
Feb 10 2018 18:39
but since it's in quotes...i have no idea ?
Aditya
@ezioda004
Feb 10 2018 18:39
@AmitP88 You can make a quick Not switch by defining a boolean in global scope say let isF = true; and then have your if statements change accordingly like
if(isF) {
              temperature.innerHTML = C;
              isF = false;
            } else {
              temperature.innerHTML = F;
              isF = true;
            }
Kyle Holm
@thekholm80
Feb 10 2018 18:40
i would think it would need href='"new 1.css"' maybe?
so the file name stays quoted
mostly just guessing though
guylozius
@guylozius
Feb 10 2018 18:41
i just changes it and it still not working
Gersho
@Gersho
Feb 10 2018 18:41

i would think it would need href='"new 1.css"' maybe?

i don't know if that exists but my first reaction upon reading it was "what the...."

Amit Patel
@AmitP88
Feb 10 2018 18:41

@ezioda004 oh yeah, I had it like this:

            if(temperature.innerHTML = F) {
              temperature.innerHTML = C;
            } else if(temperature.innerHTML = C) {
              temperature.innerHTML = F;
             }

it works, but only when it's F. After the first click and it turns to C, it won't turn back

@ezioda004 I'm seeing if I can make it into a switch case to fix this
Kyle Holm
@thekholm80
Feb 10 2018 18:43
@guylozius can you show your updated code?
@Gersho yeah, kind of ugly lol
guylozius
@guylozius
Feb 10 2018 18:44

<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">
<title>test run</title>
<link href="new1.css" rel="stylesheet" type="test/css"/>
</head>
<body>
<h1>test run </h1>
</body>
</html>

Kyle Holm
@thekholm80
Feb 10 2018 18:45
can you try changing your relative path to href="./new1.css"
Gersho
@Gersho
Feb 10 2018 18:45
@AmitP88
Please change this, it's making my eyes bleed
          var F = Math.floor(data.main.temp * (9/5) + 32) + ' ' + '&#8457';
          var C = Math.floor(((data.main.temp * (9/5) + 32) - 32) * (5/9)) + ' ' + '&#8451';
Amit Patel
@AmitP88
Feb 10 2018 18:45
@Gersho lmao ok XP
Aditya
@ezioda004
Feb 10 2018 18:45
@AmitP88 Look at this carefully if(temperature.innerHTML = F) you're assigning F to temperature.innerHTML , not comparing.
Gersho
@Gersho
Feb 10 2018 18:46
your var C is like troll maths xD
CamperBot
@camperbot
Feb 10 2018 18:46
:trollface: troll problems? notify admins here
guylozius
@guylozius
Feb 10 2018 18:46
@thekholm80 ok just did
Kyle Holm
@thekholm80
Feb 10 2018 18:46
@guylozius still not working?
guylozius
@guylozius
Feb 10 2018 18:47
yeah it not working
Amit Patel
@AmitP88
Feb 10 2018 18:47

@ezioda004 I originally tried this:

        if(temperature.innerHTML === F) {
          temperature.innerHTML = C;
        } else if(temperature.innerHTML === C) {
          temperature.innerHTML = F;
        }

```
but it didn't work, so I had to change it

Gersho
@Gersho
Feb 10 2018 18:47
          $("#temperature").on("click",function(){
            if (tempX == C){
              tempX = F;
            }else{tempX = C}
            $("#temperature").html(tempX);
          });
guylozius
@guylozius
Feb 10 2018 18:48
@thekholm80 ok just did not working
Kyle Holm
@thekholm80
Feb 10 2018 18:49
@guylozius <link href="new1.css" rel="stylesheet" type="test/css"> I don't think you need the / at the end of this tag
i can't believe how bad I am at html now. this is really sad
Aditya
@ezioda004
Feb 10 2018 18:50
@AmitP88 It works now because temperature.innerHTML = F it returns a truthy value..thats why your if statements executes and else if never does
Gersho
@Gersho
Feb 10 2018 18:50

Do Not Use Any Spaces
Just like with special characters, spaces can cause problems on your web server. It's a good idea to avoid them in your file names. I even make it a point to name files like PDFs using these same conventions, just in case I ever need to add them to a website. If you feel you need a space to make the file name easier to read, opt for hyphens or underscores instead.

For examples, instead of using "this is the file.pdf" I would use "this-is-the-file.pdf".

https://www.thoughtco.com/naming-css-style-sheet-files-3466881

guylozius
@guylozius
Feb 10 2018 18:51
@thekholm80 i just remove it and still not working'
Kyle Holm
@thekholm80
Feb 10 2018 18:51
@Gersho i always use underscores for my file names. I think it's called snake_case
Aditya
@ezioda004
Feb 10 2018 18:52
Hyphen one is called kebab-case I think
Gersho
@Gersho
Feb 10 2018 18:52
why kebab ?
you got me hungry :(
Johnny
@JohnnyBizzel
Feb 10 2018 18:52
Clearly not a kebab fan! ^^
Kyle Holm
@thekholm80
Feb 10 2018 18:52
@guylozius i'm not sure test/css is a valid type, either. can you try text/css?
Amit Patel
@AmitP88
Feb 10 2018 18:53
@ezioda004 I see
Kyle Holm
@thekholm80
Feb 10 2018 18:53
The value of the attribute should be a MIME type such as text/html, text/css, and so on. The common use of this attribute is to define the type of style sheet linked and the most common current value is text/css, which indicates a Cascading Style Sheet format.
Aditya
@ezioda004
Feb 10 2018 18:54
@Gersho That's why
TIL^
Kyle Holm
@thekholm80
Feb 10 2018 18:55
lol i've never seen a kebab that looks like a sandwich
guylozius
@guylozius
Feb 10 2018 18:55
@thekholm80 still not working
Gersho
@Gersho
Feb 10 2018 18:55
i'm i would have called that skewer-case
Kyle Holm
@thekholm80
Feb 10 2018 18:55
only a skewer with meat and veg on it
Gersho
@Gersho
Feb 10 2018 18:56

lol i've never seen a kebab that looks like a sandwich

is that banned in america too or what ? xD

Kyle Holm
@thekholm80
Feb 10 2018 18:56
@guylozius i'm sorry we've hit the limit of my html debugging expertise. hopefully someone else can help because I'm obviously not smart enough lol
Gersho
@Gersho
Feb 10 2018 18:56
let's just remove the space and call it a day ;)
Kyle Holm
@thekholm80
Feb 10 2018 18:56
he's done that
Gersho
@Gersho
Feb 10 2018 18:56
oh
Kyle Holm
@thekholm80
Feb 10 2018 18:57
hopefully he remembered to rename the file as well
so they match
guylozius
@guylozius
Feb 10 2018 18:57
yeah i already did
thanks you for trying
Gersho
@Gersho
Feb 10 2018 18:59
could it be a permission issue ? what does the console say ?
Kyle Holm
@thekholm80
Feb 10 2018 19:00
rofl
Gersho
@Gersho
Feb 10 2018 19:00
oh they even embed the tweets, cool
Sweet Coding :)
@SweetCodingInc
Feb 10 2018 19:09
@thekholm80 Ser Kyle :wave:
Kyle Holm
@thekholm80
Feb 10 2018 19:09
@SweetCodingInc hiya
how's your Saturday?
Sweet Coding :)
@SweetCodingInc
Feb 10 2018 19:09
On my way back to the US
1 hour to go for takeoff
Kyle Holm
@thekholm80
Feb 10 2018 19:10
from Germany?
did you interview?
Sweet Coding :)
@SweetCodingInc
Feb 10 2018 19:11
Haha! No! From India.. I was on vacation
Kyle Holm
@thekholm80
Feb 10 2018 19:11
oh, just as good then
Sweet Coding :)
@SweetCodingInc
Feb 10 2018 19:11
All the interviews were on skype
Kyle Holm
@thekholm80
Feb 10 2018 19:11
even better, no need for pants
Sweet Coding :)
@SweetCodingInc
Feb 10 2018 19:11
Yo!
What’s up with Silicon Slopes?
Kyle Holm
@thekholm80
Feb 10 2018 19:12
growing like crazy
Adobe is doubling the size of it's campus, hiring something like 20k more people
might have been less, my brain is garbage
yeah, i'm dumb lol they have about 1,200 people right now and they'll expand to around 2,500
i thought my number was ridiculously high
Gersho
@Gersho
Feb 10 2018 19:17
well you're stating to learn politics i guess
Kyle Holm
@thekholm80
Feb 10 2018 19:17
nah, i realized my mistake and corrected it. a politician would never do that
Gersho
@Gersho
Feb 10 2018 19:18
hence starting
Kyle Holm
@thekholm80
Feb 10 2018 19:18
lol
Gersho
@Gersho
Feb 10 2018 19:18
you'll get it eventually
Holm 2020
your next big one is 2020 right ?
Kyle Holm
@thekholm80
Feb 10 2018 19:18
maybe
if we're not a smoking hole in the ground by then
Gersho
@Gersho
Feb 10 2018 19:19
haha
by 2020, the ones eating tide pool today will be of voting age, isn't that wonderfull news ?
Kyle Holm
@thekholm80
Feb 10 2018 19:20
oh geez
Gersho
@Gersho
Feb 10 2018 19:21
btw is it true they ask for your ID to buy some now ?
ki've read it on the internet so it must be true right ?
Kyle Holm
@thekholm80
Feb 10 2018 19:22
I know a lot of lower-income areas have to keep Tide locked up because it gets stolen a lot from stores
dunno about IDing buyers though
Aditya
@ezioda004
Feb 10 2018 19:28
On one hand we have synchronous rocket landing and in other kids eating tide pod.
Balance restored.
Gersho
@Gersho
Feb 10 2018 19:29
too bad i'll be dead by the time space tourism is a thing
Kyle Holm
@thekholm80
Feb 10 2018 19:30
I'm kind of sad about that too
Aditya
@ezioda004
Feb 10 2018 19:30
Unless we achieve transcendence
Kyle Holm
@thekholm80
Feb 10 2018 19:39
lol
Gersho
@Gersho
Feb 10 2018 19:41
aren't they forgetting the 95% of pron ?
Kelechi Chinaka
@ke1echi
Feb 10 2018 20:17
:wave: guys
Gersho
@Gersho
Feb 10 2018 20:17
@kelechy :wave:
i saw on the news Nigeria has a bobsleigh team, that was unexpected
Kelechi Chinaka
@ke1echi
Feb 10 2018 20:20
lol
yea
hows it going with you @Gersho
Gersho
@Gersho
Feb 10 2018 20:23
slow progress but progress still :)
how about you ? done with cash.c ?
Kelechi Chinaka
@ke1echi
Feb 10 2018 20:26
yea
want to do credit
is there a way to convert a number to string in c?
Gersho
@Gersho
Feb 10 2018 20:27
oh that one, it gave me trouble a bit
i'm checking what i wrote, that was only a couple weeks ago and i feel like i'm reading someone else code >.>
Kelechi Chinaka
@ke1echi
Feb 10 2018 20:28
:smile:
Gersho
@Gersho
Feb 10 2018 20:29
i did not convert it to string
Kelechi Chinaka
@ke1echi
Feb 10 2018 20:29
i did the luhn algo with CW
Gersho
@Gersho
Feb 10 2018 20:30
i used % 10 to get last digit then / 10 to shift and did that until i had checked every number
Kelechi Chinaka
@ke1echi
Feb 10 2018 20:30
but i coverted to a string in js
so i can iterate over the credit number
Gersho
@Gersho
Feb 10 2018 20:32
my itteration is done that way
    // cn is card number
    long long cn = n;
    int temp;
    // Will store the number of digits in the card number
    int cnlength = 0;
    int total = 0;
    while ( cn > 0 )
    {
        // Itterate every digit starting from the right
        temp = cn % 10;
        cn /= 10;
        cnlength++;
       // do stuff with temp
   }
it will itterate every number starting from the right
Kelechi Chinaka
@ke1echi
Feb 10 2018 20:38
i want to start from the left and do sometime to element at odd index
Gersho
@Gersho
Feb 10 2018 20:39
why from the left ? the odd and even index are based on the right in a credit card number
but if that really what you want, i guess you could create an array ? (in the "do stuff with temp") part
Kelechi Chinaka
@ke1echi
Feb 10 2018 20:41
yea thats true
Gersho
@Gersho
Feb 10 2018 20:44
still i wonder how the math guys come up with stuff like that, almost feel like my mom's numerology books
Kelechi Chinaka
@ke1echi
Feb 10 2018 20:45
:smile:
could your solve the algo with js
Gersho
@Gersho
Feb 10 2018 20:48
js ? i've never tried
Gersho
@Gersho
Feb 10 2018 20:52
well, should be easier than in C, but i'm lazy :P
Kelechi Chinaka
@ke1echi
Feb 10 2018 20:53
yea certainly easier than C
you have to do almost everything yourself in C :smile:
Gersho
@Gersho
Feb 10 2018 20:54
for the js CW, i guess i'd remove the spaces, and then itterate with a for loop starting at the end like
for (i = str.length; i >= 0; i--){
//do stuff
}
Kelechi Chinaka
@ke1echi
Feb 10 2018 21:11
i will do the credit tomorrow @Gersho
Kelechi Chinaka
@ke1echi
Feb 10 2018 22:04
still there? @Gersho
Gersho
@Gersho
Feb 10 2018 22:06
depending on my internet
Kelechi Chinaka
@ke1echi
Feb 10 2018 22:07
i think i need an extra eye
Gersho
@Gersho
Feb 10 2018 22:07
sure, i've got 4 of those i can help
dont know if i missed sometime in description
function validCard(card) {
  card = card.replace(/ /g,""); let n = "";
  for (let i = card.length-2; i >= 0; i-=2) {
    n+=(card[i]*2)>9 ? (card[i]*2)-9 : card[i]*2 ;
  }
  return n.split``.reduce((a,b)=>a + +b,0)//%10===0;
}
Gersho
@Gersho
Feb 10 2018 22:08
oh the one from earlier, but i can't see your code you'll need to paste it ^^
shouldn't it be let n = 0 ?
also, you're doing the multiply *2 on the odd ones but shouldn't be adding the others too (without multiplying)
Kelechi Chinaka
@ke1echi
Feb 10 2018 22:11
no n is a string, since i need to sum the digits
not stated in description
Gersho
@Gersho
Feb 10 2018 22:12
won't that end up with problems like "2" + "2" = 22 ?
you could try using integers along with parseInt on card[i]
so you keep card as a string to allow easy itteration, while using intergers for the sum
Kelechi Chinaka
@ke1echi
Feb 10 2018 22:15
CS50 and the kata decrptions are different
Gersho
@Gersho
Feb 10 2018 22:15
oh well then skip the part the kata doesn't ask for
Kelechi Chinaka
@ke1echi
Feb 10 2018 22:16
i am using the kata's description to solve it
Gersho
@Gersho
Feb 10 2018 22:16
hmm second dot says sum all digits, but the way it's worded is weird
Kelechi Chinaka
@ke1echi
Feb 10 2018 22:16
did you see the kata description?
Gersho
@Gersho
Feb 10 2018 22:16
yep, i think you should take a look at the wiki page linked too
Kelechi Chinaka
@ke1echi
Feb 10 2018 22:17
very weird, thats why i did n to be string Take the sum of all the digits.
Wasiu Idowu
@Hoxtygen
Feb 10 2018 22:17
Hello guys, I need help on a PHP script
Gersho
@Gersho
Feb 10 2018 22:18
i don't know PHP-fu sorry
Kelechi Chinaka
@ke1echi
Feb 10 2018 22:20
i need a fresh pair of eyes to look at this @Gersho
Gersho
@Gersho
Feb 10 2018 22:21
sure, what part ?
Kelechi Chinaka
@ke1echi
Feb 10 2018 22:23
post your questions and someone with experience would drop an answer @Hoxtygen
i just can point fingers now, the description is poorly written imo @Gersho
Take the sum of all the digits. or do they mean the whole digits in card? @Gersho
Gersho
@Gersho
Feb 10 2018 22:30

well, let's see an exemple, should be easier:

123456789 as the card number
we would do
8x2 + 6x2 + 4x2 + 2x2
(1+6 =>7) + (1 + 2 => 3) + 8 + 4 => 22
9 + 7 + 5 + 3 + 1 => 25
22 + 25 => 47
47 % 10 => if 0, card is valid

that's how i understand it anyway

Kelechi Chinaka
@ke1echi
Feb 10 2018 22:44
function validCard(card) {
  card = card.replace(/ /g,"").split``;
  for (let i = card.length-2; i >= 0; i-=2) {
    card[i] = (card[i]*2)>9 ? (card[i]*2)-9 : card[i]*2 ;
  }
  return card.reduce((a,b)=>a + +b, 0) % 10 === 0;
}
done @Gersho
Gersho
@Gersho
Feb 10 2018 22:46
i don't understand the 2 + in the reduce
Kelechi Chinaka
@ke1echi
Feb 10 2018 22:48
coerce the string "4" etc to 4
Gersho
@Gersho
Feb 10 2018 22:48
oh, ok
btw i like you usage of the array and the reduce
Kelechi Chinaka
@ke1echi
Feb 10 2018 22:49
the kata and cs50 description are different
Gersho
@Gersho
Feb 10 2018 22:50
if they are both about the same algo, it shouldn't be different