These are chat archives for FreeCodeCamp/HelpJavaScript

19th
May 2018
Mike Haslam
@Ongomobile
May 19 2018 00:16

Hello hope everyone is well, I am having trouble adding home screen icons to create react app
In manifest.json I have many sizes example

{ "src":"/images/icons/apple-icon-57x57.png",
“type”: “image/png”,
“sizes”: “57x57”,
}

in index.html links look like this

<link rel="apple-touch-icon" href=“%PUBLIC_URL%images/icons/apple-
icon-57x57.png" sizes="57x57" />

The icon files are in public/images/icons.

Thanks for having a look

Mike Haslam
@Ongomobile
May 19 2018 00:34
@ndburrus thanks I will look in those maybe I can spot my error
CamperBot
@camperbot
May 19 2018 00:34
ongomobile sends brownie points to @ndburrus :sparkles: :thumbsup: :sparkles:
:star2: 2226 | @ndburrus |http://www.freecodecamp.org/ndburrus
Norvin Burrus
@ndburrus
May 19 2018 00:36
@Ongomobile you're welcome! enjoy :golf:
kerafyrm02
@kerafyrm02
May 19 2018 06:48
Anyone need help?
dinesh
@1532j0004kg
May 19 2018 06:48
In passport js?
kerafyrm02
@kerafyrm02
May 19 2018 06:54
Ok i guess noone needs help
i'm out for the nite
Rajat
@rajataudichya
May 19 2018 07:55
guys I m bulding the local weather machine any luck with api?
Ramesh
@rnallu
May 19 2018 10:06
toggle function is not showing the default to click , can anyone help on this.
    navigator.geolocation.getCurrentPosition(function(data){
        var latit = data.coords.latitude;
        var longit = data.coords.longitude;
        var jsonUrl = "https://fcc-weather-api.glitch.me/api/current?lat="+latit+"&lon="+longit;

        $.getJSON(jsonUrl, function (data){
            var degree = data.main.temp;
            $("#temp").text(toggle(toC,toF));
            $('#locate').text(data.name +" " + data.sys.country);
            $('#weatherDesc').text(data.weather[0].main);
            document.getElementById('weatherImg').src = data.weather[0].icon;

    });

    });

    function toC(degree){
        return degree+String.fromCharCode(176)+"C";
    }

    function toF(degree){
        return (degree*1.8+32)+String.fromCharCode(176)+"F";
    }
Stephen James
@sjames1958gm
May 19 2018 10:38
What is toggle function?
Ramesh
@rnallu
May 19 2018 10:41
its switching between two functions
Stephen James
@sjames1958gm
May 19 2018 10:42
How do those function get passed degree?
Are you getting ‘undefined C’ or something like that?
Ramesh
@rnallu
May 19 2018 10:46
its not showing anything to click , i mean to activate the toggle function
Stephen James
@sjames1958gm
May 19 2018 10:49
Where is the toggle function defined?
Ramesh
@rnallu
May 19 2018 11:10
toggle is builtin function of jQuery
Stephen James
@sjames1958gm
May 19 2018 11:17
@rnallu toggle has to be called on an element - you are calling it without an element
Unless there is a different toggle. Do you have a link to the docs for that function?
Anyway, toggle(toC, toF) if toggle were to call these two functions - it wouldn't have a way to pass in the degree parameter
Dimitris Nik.
@dimitrissnk
May 19 2018 20:47
Hello, it is possible to use a variable as the URL string in the getJSON() property,right?
so insteat of having $.getJSON("https://something.com/file", function()... have this one: $.getJSON(variable, function()...
Gulsvi
@gulsvi
May 19 2018 21:12
@Dimitrios51 Yes, using a variable is a great way to do it. For example:
var tokyoWeather = "https://fcc-weather-api.glitch.me/api/current?lat=35&lon=139";

$.getJSON(tokyoWeather, function(data) {
  $("body").append("Current temperature in Tokyo is: " + data.main.temp + "&deg;C");
});
ArchivalBoat50
@ArchivalBoat50
May 19 2018 21:17
Hey guys, I am doing the Truncate a string algorithm but I don't know why it's giving me a 'length' of undefined. Can someone help me understand?
function truncateString(str, num) {
  var sliced = str.slice(0, num);
  var truncate;
  if (str.length > num) {
    truncate = sliced + "...";
  }
  else if (truncate.length > num) {
    truncate = sliced.slice(0, num - 3) + "...";
  }

 return truncate;
}

truncateString("A-tisket a-tasket A green and yellow basket", 43);
When I enter num in as a number less than 43, everything seems to be on point, but I don't know why that 43 number being the length of str is giving me an undefined.
Dimitris Nik.
@dimitrissnk
May 19 2018 21:22
@gulsvi Okey, I am trying to do that so but I always get an error in the console that my variable is undefiend, although I have defined it outside the function
Bjorn van de Peut
@bjorno43
May 19 2018 21:29
@ArchivalBoat50 truncate.length this is your problem. The length property doesn't work on a variable with no value assigned to it. So even though you're declaring it with var truncate;, there's no length to calculate. Just change it to var truncate = ''; and the issue is solved.
Though your code will most likely not work as neither condition will return true
Gulsvi
@gulsvi
May 19 2018 21:33
@Dimitrios51 Sorry for the delay, just stepped away. If you can share your code, I'm happy to take a closer look
Dimitris Nik.
@dimitrissnk
May 19 2018 21:35
@gulsvi no problem. Check out my pen https://codepen.io/dimitris51/pen/jzjaOX
It is on line 27
And as you can see, I have defined all variables outside the functions, so they are in global scope?!?
Gulsvi
@gulsvi
May 19 2018 21:38
@Dimitrios51 The problem here is an asynchronous issue - one of the things this project teaches us. Getting the location takes some time, so $.getJSON is called before the location comes back. As a result, we can't use global variables when calling APIs or getting the location - all variables have to be locally defined, or we have to pass them to another function.
Dimitris Nik.
@dimitrissnk
May 19 2018 21:41
@gulsvi «asynchronous»,I have seen this word a lot today. So, how can this be fixed?
Gulsvi
@gulsvi
May 19 2018 21:42
You can move your getJSON to the showPosition function or create a new function like getWeather() to put your getJSON in, and then call it from your showPosition function. Like:
function showPosition(position) {
    var latitude = position.coords.latitude; 
    var longitude = position.coords.longitude;
    var url = "https://fcc-weather-api.glitch.me/api/current?lat=" + latitude + "&lon=" + longitude;
    getWeather(url);
}

function getWeather(url) {
    $.getJSON(url, function(data) {
         ....
    });
}
We pass the data around from one function to another this way @Dimitrios51
Bjorn van de Peut
@bjorno43
May 19 2018 21:43
Was just about to say that, lol. Just wrap the xhr call into a function and call it from the function that returns the location. Beat me to it :P
Gulsvi
@gulsvi
May 19 2018 21:44
I think that's the cleanest way to do it - separate logic into functions and have each function do no more than 1-2 things.
Dimitris Nik.
@dimitrissnk
May 19 2018 21:44
@gulsvi Can you open and try it now? It should work
Gulsvi
@gulsvi
May 19 2018 21:45
@Dimitrios51 Yep, works great :)
You can remove lines 2-3 now
And move your var url into the showPosition function - don't make any global variables
Bjorn van de Peut
@bjorno43
May 19 2018 21:46
Well I guess you could make a callback function and pass the xhr function along, but that's a bit out of the scope of this lesson, ghehe
I'm rly having my doubts about what I should do next. I've got 2 projects in mind, I just can't make a decision on which one to focus on
Dimitris Nik.
@dimitrissnk
May 19 2018 21:51
@gulsvi thanks for that my friend :D
CamperBot
@camperbot
May 19 2018 21:51
dimitrios51 sends brownie points to @gulsvi :sparkles: :thumbsup: :sparkles:
:star2: 2724 | @gulsvi |http://www.freecodecamp.org/gulsvi
Bjorn van de Peut
@bjorno43
May 19 2018 21:51
The first project is my own Codepen / jsFiddle with operational transformation (collaborative editing). The second one is a workflow / ticket system for small to mid- sized companies
Gulsvi
@gulsvi
May 19 2018 21:51
Any time! @Dimitrios51
Dimitris Nik.
@dimitrissnk
May 19 2018 21:51
@bjorno43 what projects? Do they have to do with money or just learning?
Gulsvi
@gulsvi
May 19 2018 21:52
Yeah, was wondering - if no priority for one over the other, maybe a third project can be a project picker app :)
a.k.a flip a coin lol
Bjorn van de Peut
@bjorno43
May 19 2018 22:04
@Dimitrios51 Well, the first project is about learning, the second about money. The issue is that operational transformation is pretty much only supported with Node or Python backends. And my knowledge is mostly PHP backends. All of my servers also only have PHP available as a backend. Even though I've got root access (obviously) and I could install Node on them, there's the conflict part with Apache and I'd have to mess around with Proxies to get it to work. So the easy choice would be the second project. But the first project is where most my interest lies
Kudzu
@czhower
May 19 2018 22:05
Thats not quite true Bjorn - devs suffer from bubbles they work in. There are tons of backend in Java, .NET etc....
aah sorry, I misread your statement,. I thought you said most were PHP, just reread and noticed you said it was most of your backends.
Bjorn van de Peut
@bjorno43
May 19 2018 22:07
Ghehe no problem. Obviously operational transformation could be done with any backend if you have the knowledge required for it. But I don't. There aren't many libraries out there for it (most are no longer maintained because of the difficulties that come with it) and those that still are, are based on Node or Python
Kudzu
@czhower
May 19 2018 22:08
C# and Java backends are very common, especially in Enterprises. Those that start in the scripting world though and stay there never really see the huge amounts in GPs.
C# is really big, and in raw numbers Java is massive and even bigger. .NET is gaining though with .NET core and a lot of Javas numbers are pure momentum. Its not a horrible platform (Java), just worth noting that a lot of it is momentum based.
Bjorn van de Peut
@bjorno43
May 19 2018 22:10
I'm reasonably good with C#, but I've never done anything with it on the web. Let along something as complicated as this
Kudzu
@czhower
May 19 2018 22:11
The main thing that sucks about Java is language lock in - of course this has changed a bit in recent years but non Java langs on on Java platforms are still second class citizens a bit and not that common overall, while in the .NET world there are tons of langs.
And the server side stats you need to interpret.. PHP is huge becuase of WordPress and PHPBB etc.... I dont really count package software, especially ones like that but the stats do. Also the stats dont count Enterprises as their servers are not public or are restricted - and Enterprises heavily favor Java, C#, etc.
server side stats are PHOP 83%.. but thats WP.. better to also look at jobs:
blob
And even that takes interpreation, becuase most JS jobs are low level jobs. its like saying that ther are more employees at WalMart than at Brain Surgery.
Kudzu
@czhower
May 19 2018 22:16
As you can see here. Java is still the king. I'm not a Java fan (nor a hater) but it is the king and has been for a while.
Its all because Enterprise work is very different than public web work and that is where most JS devs are and most of them never see the Enterprise side of things.
Bjorn van de Peut
@bjorno43
May 19 2018 22:17
Ye you're right. Unlike most, I don't hate Java. I never rly came across a good reason to hate it, aside from memory issues that everyone keeps talking about. But when you plan to do something, you tend to fall back on the technologies you're familliar with and prefer not to learn a completely new one just for a single goal
Kudzu
@czhower
May 19 2018 22:18
I have technical reasons that I dont prefer Java but it is a very capable platform and the language is decent enough. It just has a lot of little things that grind me the wrong way and drive me nuts.
Capability wise it and .NET are pretty even especially now that .NET is cross platform. But Java has massive momentum.
Java is the modern mainframe.
And has many of the same customers.
if $$ was my driver, then I might have to be less choosy, but I have the ability in most cases to choose my langs, so I prefer to choose langs that work closest to my brain coding style :)
Bjorn van de Peut
@bjorno43
May 19 2018 22:21
Well $$ isn't rly my drive. I mean, it's cool to benefit a bit of my work, but it's more about keeping myself busy than making tons of money.
Kudzu
@czhower
May 19 2018 22:24
Im surprised you still do so much PHP then... its so rare to find a dev who doesnt at least dislike PHP.
I do only a tiny bit of PHP and its only becuase with WordPress there is no other choice, but we use it as a small shim to then proxy out to other services when possiblr.
Bjorn van de Peut
@bjorno43
May 19 2018 22:25
I spend a lot of my time here on FCC and on Stack Overflow helping out ppl with questions. Sometimes however, more in depth help is required. In such situations it'll be great to be able to work together with those ppl on their code. Obviously you have solutions like Teamviewer for that, but most ppl (understandably) have trust issues inviting a stranger with a Teamviewer session. That's where a Codepen / jsFiddle like project with colaborative editing could become extremely handy. And that's why I'm interested in developing something like that
Kudzu
@czhower
May 19 2018 22:25
I may have to do a bit more soon though to get some of our stuff to run on a shared host, but I think we hopefully can get node running there so we can use TS.
Certainly a need. VS (not VS Code) now has the ability to share code in the IDE remotely with team etc. I havent used it, but its a good direction there too.
Hopefully some day VS Code and Atom will get some things like that.
A huge issue I see among JS devs is that they stay in codepen etc for a long time and never ever learn about even the JS debuggers in the browsers let alone Atom / VS code.....
Kudzu
@czhower
May 19 2018 22:30
Mention watches and breakpoints and they have no clue.... they are debugging using console or window.alert
I think more guidance should be given to teach them the JS debugger in the browser and then later move them to VS Code / Atom.
Bjorn van de Peut
@bjorno43
May 19 2018 22:33
Ye that kind of collaboration is exactly what I'm talking about. If you go here: https://www.icecub.nl/PairProgramming/#-LCuWbJTcykwh4_ujWhE , please don't mind the outdated SSL certificate, still have to fix that, you'll see I already have it working using Firebase
Kudzu
@czhower
May 19 2018 23:18
Cool. I think it was you who had me test this early on back in Dec or so of last year.. if not you then someone doing something similar.
Bjorn van de Peut
@bjorno43
May 19 2018 23:29
Probably me. I've been on it for quite some time now. But ye, that system is completely dependent on Firebase. It works, but each single edit writes to the database backend and the "free" version only allowes 20k edits / month. So it's fun the mess around with, but not usefull in any production environment. That's why I want to do it completely independent of some service