• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Web Design and Development |OT| Pixel perfect is dead, long live responsive design

I was wondering if anyone would have any experience or advise regarding internships in the UK. Basically I started teaching myself front end web development around 3 years ago, and lately I have been trying to get into a full time role. However I am really struggling to break into the industry because I don't have any commercial experience (from what I am told in feedback). Anyway, I applied for a role last week and they have just come back to me to say:

We have conducted several interviews this week as mentioned on the phone. We have had some recent graduates come in with some good knowledge and experience and feel that they could hit the ground running because of this. I still feel it may be good to invite you in for a chat to find out more about you and your skill/experience levels to see if we could potentially offer a summer internship type of thing and see how that goes in terms of the progressing into something more permanent.

The problem I have is that I have a pretty secure, full time job, with a good salary (just not in the field I want to be in). I would have no hesitation about going for a job with less money (I would even consider minimum wage), but I am not too sure what to expect from an internship. Has anyone else had any experience with internships? I am planning on going in for a chat regardless, but I was wanting to call up and get a bit more information.
 
I did a summer internship more than a year before I finished school. The company hired once I got out.

Internships / portfolios / hobby projects count a lot when it comes to sifting through applications from fresh grads. I have seen a company who will just chuck your application straight into the bin if you never did any coding outside school.

If you can secure than internship (as in signed contract, not just verbal agreement), and you're dead set into the field, I'd suggest taking it. I should emphasize the signed contract part, because a verbal agreement or a job offer can be rescinded anytime for any reason especially for internships.
 
I did a summer internship more than a year before I finished school. The company hired once I got out.

Internships / portfolios / hobby projects count a lot when it comes to sifting through applications from fresh grads. I have seen a company who will just chuck your application straight into the bin if you never did any coding outside school.

If you can secure than internship (as in signed contract, not just verbal agreement), and you're dead set into the field, I'd suggest taking it. I should emphasize the signed contract part, because a verbal agreement or a job offer can be rescinded anytime for any reason especially for internships.

I am definitely leaning towards pursuing it, I am just a little worried that I could be unemployed at the end of it.
 

Daffy Duck

Member
Sounds like it could be a foot in the door you want, however I would be very eager to get some assurances on what it will lead to and if that is a full time job at the end of it.
 

Lister

Banned
I'm trying to get this script working on a page, but it's not working and I'm sure I did everything correct. What's going on?

We'll probably need more info than that to help you.

To start, are you sure you have both jquery and this extension loaded before your own script? Are you sure you are referecing the target element correctly by id or class?
 
We'll probably need more info than that to help you.

To start, are you sure you have both jquery and this extension loaded before your own script? Are you sure you are referecing the target element correctly by id or class?

I copied the examples exactly. I have jquery near the bottom of the page and that extension after it.
 

GHG

Gold Member
I copied the examples exactly. I have jquery near the bottom of the page and that extension after it.

If you copied the examples exactly then it means the JS isn't wrapped in a script tag. Did you wrap the JQuery in a script tag? If not, wrap it in a script tag and see if that gets it working.
 

Zakalwe

Banned
Can anyone give me some advice on how to deal with clients not reading emails with detailed info/instructions?

When we begin a project I always let the client know that the deadline is conditional on both of us. If I have to wait 2-3 days for a response I need to continue, that's 2-3 days I will have to potentially make up pushing the deadline back.

I also have other jobs scheduled so often can't afford this loss of time. Beyond making this clear at the start I'm not really sure how to handle it.

A couple of times I've had to send a text/email or even all a client to prompt a response after a couple of days radio silence, but I don't want to be too pushy with it.

Here's a a few examples of what I've dealt with lately:

Site is complete. I send the client a detailed email explaining what happens next:
-- Need to arrange handover of raw site files and upload to their hosting.
-- Need to make any reasonable last minute changes/additions.
-- Need to either meet in person or arrange a way for me to explain how to use the editing software.
-- Need to set up any private email accounts they need.
-- Need to receive final payment.

All in simple, concise language and with as much detail as to be idiot proof.

No response for 2 days. I send a text asking politely "did you have a chance to look over the email? We need to arrange handover and get your site uploaded!", I get in response "not sure what you mean but whatever", "sent you payment", "how do I edit things if I want to?".

It's all in the email...

Now this has happened on the last two jobs for almost every single step.

-- I asked a client for a response on the initial design, nothing for 3 days. When I finally get a response it says nothing about the design and asks an unrelated question.

-- I provided a list of things I need from the client (a juice bar), including: images, logo, menu, copy, anything else they'd like to include. I get an email back a few hours later with a couple of dodgy mobile phone images (with the person taking the picture reflected in the storefront), and nothing else. 2 days later I have to prompt for the rest. In the end I have to hunt through their social media for images myself and hope they're suitable.

-- All my emails are written politely, clearly, and assure the client they can call me at any point during working hours (9-7 for me) with any questions they may have. I go out of my way to make sure I come across friendly, professional, confident, etc... I'm not really sure how else to approach this.

All my clients are small business owners so far, so perhaps it's just a matter of every day people not understanding how a client/developer relationship needs to be on a professional level, but it's becoming quite frustrating having to wait for days for a response, and finally getting a response that doesn't even attempt to answer my questions or requests.

Anyway, apologies for the wall. Just a bit frustrated here and not quite sure how to adapt the way I'm doing things to overcome this issue.

Any advice welcome.

-

PS - my latest client forwarded his the emails between him and the designer who made their menu, and it was clear the designer was getting fed up with the client's lack of ability to read too, to the point their answers became more and more blunt and less forgiving. My own never do this, but perhaps I need to find a way to be more stern while staying professional?

I might be letting my clients walk over me by worrying about being too polite, I'm not sure what the correct balance is here.
 
If you copied the examples exactly then it means the JS isn't wrapped in a script tag. Did you wrap the JQuery in a script tag? If not, wrap it in a script tag and see if that gets it working.

It definitely looks correct. I took out everything from my page and just added the scripts.
Code:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
  </head>
  <body>

  <span id="clock"></span>
  
  <script type="text/javascript">
  var date = new Date(new Date().valueOf() + 15 * 24 * 60 * 60 * 1000);
  $('#clock').countdown(date, function(event) {
    $(this).html(event.strftime('%D days %H:%M:%S'));
  });
</script>

  <script src="http://code.jquery.com/jquery.js"></script>
  <script src="http://cdn.rawgit.com/hilios/jQuery.countdown/2.2.0/dist/jquery.countdown.min.js"></script>  
  </body>
</html>

But that doesn't work.
 

Lister

Banned
It definitely looks correct. I took out everything from my page and just added the scripts.
Code:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
  </head>
  <body>

  <span id="clock"></span>
  
  <script type="text/javascript">
  var date = new Date(new Date().valueOf() + 15 * 24 * 60 * 60 * 1000);
  $('#clock').countdown(date, function(event) {
    $(this).html(event.strftime('%D days %H:%M:%S'));
  });
</script>

  <script src="http://code.jquery.com/jquery.js"></script>
  <script src="http://cdn.rawgit.com/hilios/jQuery.countdown/2.2.0/dist/jquery.countdown.min.js"></script>  
  </body>
</html>

But that doesn't work.

You need to move your script AFTER both the jquery and extension imports.

To debug your script hit F12 in chrome to open up the console. There should be an error there about $() not being defined. The jquery script adds a global variable "$" which is what you are using in your script. But since you are attmepting to use it before it is defined by jquery.js, execution will fail.
 
You need to move your script AFTER both the jquery and extension imports.

To debug your script hit F12 in chrome to open up the console. There should be an error there about $() not being defined. The jquery script adds a global variable "$" which is what you are using in your script. But since you are attmepting to use it before it is defined by jquery.js, execution will fail.

Oh, okay. I didn't know how to debug such an error like that. Looking at the example page more closely, I see the scripts are added between the head tags of the page. That looks like it would also solve that problem.
 

Every client is an idiot, and they're all special idiots and idiotic in their own ways.

What helps me the most when communicating with clients is to end the email with a prompt for them...

"
[list of stuff I need, etc]

Let me know when you think you can put these materials together so that I can get started.
Thanks!
- Jimbo"

Or

"[list of stuff]
Take a look at the list above and let me know if you have any questions.
Thanks!
- Booboo"

I usually try to put the honus of responsibility on them, mostly just with subtle wording. Like you showed, I'll put a list of points/requirements/questions, and then usually wrap it up with something that implies "I can't work unless you do these things," but in a nice way. I usually don't try to use insider phrases like "handoff," "launch," or anything, because you've got to figure this may be the first process for a website, and they don't know that materials get handed off, and then I work on it, and then connect back with them, etc. Saying, "We need to arrange handover to get your site uploaded!" won't make a lot of sense to people who don't know what those words mean in that context. They may know what "handover" and "uploaded" means in another context, but maybe not the context of their website.

I have a few rules when it comes to working, but one of them is to remind myself that the people I'm talking to don't do what I do for a living, and it's something I have to really constantly tell myself when communicating because it's easy to fall back on assumptions that someone knows something that you might take for granted as a developer. I know that when I'm working with service in some other sector, I get frustrated when somebody seems to assume that I should know something... Like last week I was setting up car insurance for our new car, and my insurance agent sent me an email using a bunch of acronyms that I had no idea what they mean... "Send the PW and RMV1 over to me and I can process them monday!" was somwthing she said to me, and ... I was frustrated because, fuck it, I don't know what a PW or RMV1 is (to me, PW means 'password' but to her, it meant 'paperwork.'), and I wanted to say to her "Listen, Charlene, pretend that I don't work in the insurance industry every day, ok?"

So one of my rules of working is just to remind myself that the client doesn't do this every day... THey don't know what's involved, and they're usually focused on running their business, while their website is one aspect of something that they just want to "get done." Of course, at some point, it gets frustrating to continually not get what you need to do a job, so the best way is to keep following up... I usually send friendly prompts and list out what I need again.

"Hey Gary,
I'm looking forward to starting work on this web project. When you have a chance can you review these items below and get back to me? Once I have this information I can get things moving:

1...
2..
3..

Let me know if you have any questions or if I can help answer those for you.
Thanks!
Bobo"

If the client says something like, "I dont know what you're talking about whatever" then I might consider dropping them, because they may not really care about their website. To me, it's like if I was having an addition put onto my house and the builder was trying to ask me if I wanted a bathroom or a kitchen addition, and I just said like, "oh I dunno just do whatever," that would be a red flag for the builder. Likewise, if a client isn't invested in their site, then they might not be right. And as long as you communicate that you can't get started working without X,Y,Z information, then the responsibility is on them to get that info to you.

Two days for them to respond isn't bad though. In my experience, most business owners might set aside a particular day of the week to worry about things like "the website." And so they may get your email, see it's a long list, and say "Eh, I'll look at that on Thursday..." and then Thursday comes along and they don't really reply until Friday at 4:48PM, 10 mins before they go home, and they don't give you all of the information you need and so you're left asking more questions. THis is common and the best approach is just to follow up... "Thanks for this info Bob, it should help move things along. Unfortunately I'll still need A, B, and C... LEt me know if I can help pull that together with you. Thanks!"

But, ultimately, communicating is one of the biggest challenges in any job.

In my post I mentioned "I have a couple rules of working," and while one of them is reminding myself that the client doesn't do my job, the second one is a simple saying... "Do what you say you will do." If you follow that rule, you'll build credibility with your clients. It's really easy to say "Hey Pat, I'll work on this task this weekend and will have it finished soon!" and then you don't really work on it, and then it's a week later...... and you just kinda push it off. Or the client asks for an update and you say "Planning to have it all finished on Monday!" and Monday is coming up and you know it's not really finished... The best approach is just "Do what you say you will do." If you say you're going to do something, do it, if you aren't going to do something, don't say you're going to. It's okay not to do something as long as you don't say you're going to do it. It's a surprisingly hard rule to follow, and at times it can be really easy to want to allay someone's concerns and tell them something that you don't really think you can do, and get them off your back... But it's far better to follow the rule in the long run. And, if you say you're going to do something, and you realize you can't, there's no harm in telling them... Most people don't mind delays as long as you're up front about it.

Also I'd keep everything in email. Don't text them. Keep a written email record in one or two email threads, it makes it much much easier to reference later.

For Pay though... fuck em. Send em an invoice when the work is done. A lot of people respond to something when you're asking for money. Send them the invoice due in 30 days, if they don't reply within a couple of weeks, follow up with, "Hey John, just following up to see if you received this invoice. No rush, it's not due for another couple weeks but just wanted to make sure there weren't any problems. Thanks! -Barry." If it hits 30 days, depending on the client, is when your tone changes. If it's a client you like, be friendly and say, "Hi John, have you had a chance to process this invoice? It's overdue, but let me know if there are any issues." And then the next one, "HI John, this invoice is overdue by 15 days. Please let me know when you've processed it. Thanks, Barry." If it goes longer than that just stay persistent on a regular cadence. I had one client not pay for about a year, and I basically gave up except I sent an automated invoice email to them every two weeks. I figured I'd never be paid and had mostly written it as a loss, it wasn't a lot of work, but it was annoying to have it hanging out there. Eventually they randomly paid me, but the issue was that they were basically about to declare bankruptcy.... Of course, when they did pay me the owner sent me this emaila bout how she wanted to totally redesign the site soon, etc., and I was just like "oh..... sure... good luck" to myself.
 

GHG

Gold Member
Can anyone give me some advice on how to deal with clients not reading emails with detailed info/instructions?

Get some terms and conditions written up, along with a schedule of work and make the client sign them before agreeing to start work. That way if the client decides to ignore emails or not respond in the time set out in the terms and conditions which makes the project timeline slip then they are at fault.

Clients will rarely read your emails properly, they will rarely do what you ask of them on time so therefore you need to protect yourself. For example in my terms I state that my company will not start work until they have signed off on wireframes and paid the pre-agreed initial percentage of the total project cost up front. I also state that if at any point during the project they do not respond to an email requesting required materials within 72 hours then the project will be placed on hold until they respond. These are little things that give clients the kick up the backside that they need.

If you are too subtle then they will take you for a ride. The saying goes give them an inch and they will take a mile. If you are going to give them an inch, make sure it stays an inch.
 

Zakalwe

Banned

Right, I'm going with the "every client is an idiot" approach from now on and adding to my contracts. Something along the lines of what you wrote for sure.

I mean, I thought what I was offering was idiot-proof, like I even went as far as taking screenshots and making visual guides for certain things that the client(s) then called me and asked "how do I do this?".

I think I'll try to make it clearer that emails must be read if the build is going to go efficiently, I might even go as far as a daily email that includes any essential things and make sure the client knows they need to view it. Some days it will have nothing and just a note saying "we're all on schedule, no concerns my end", others it will have a list of needed things.

I think I'll also put together a generic template for a welcome package of sorts. The initial email I send that includes the contract, invoice, and a well thought out and simple explanation of the process. I'll ask the client to make sure they read this and let me know via email they're happy before we begin. I mean, I do this now but I'll make it a kind of milestone that must be passed before we can begin.

I currently have no issue with being paid. I insist on 50% up-front and the rest on handover. I upload the site to my own server, and don't transfer to the client until payment has been received. So they can't use the site with their URL or edit it themselves until we're square.

No problems so far, we'll see how it goes...

Oh, and I'm /very/ disciplined when it comes to doing what I say when I say. Right now I'm even way ahead of it in that I often finish up stuff in my free time to get it done. I'm very focused on my work and improvement in terms of both design and development, and I really love what I do, so I tend to work very diligently and quickly. This is definitely paying off in terms of word of mouth recommendations and how the clients respond overall.

I'll think on all of this, thanks very much for the detailed response. Your experience is a real help here.



Get some terms and conditions written up, along with a schedule of work and make the client sign them before agreeing to start work. That way if the client decides to ignore emails or not respond in the time set out in the terms and conditions which makes the project timeline slip then they are at fault.

Clients will rarely read your emails properly, they will rarely do what you ask of them on time so therefore you need to protect yourself. For example in my terms I state that my company will not start work until they have signed off on wireframes and paid the pre-agreed initial percentage of the total project cost up front. I also state that if at any point during the project they do not respond to an email requesting required materials within 72 hours then the project will be placed on hold until they respond. These are little things that give clients the kick up the backside that they need.

If you are too subtle then they will take you for a ride. The saying goes give them an inch and they will take a mile. If you are going to give them an inch, make sure it stays an inch.

Right, this all makes sense. I'll think back on my past projects and come up with some reasonable guidelines for the future.

Thanks very much for your input, same as above! :)
 
Sorry for asking too many questions, but I'm not faced with another somewhat complicated thing I have to implement.

I have a section like this.


I have this grid of 12 items that when I click, will make the section below populate with its items (so it's like a tab system). But for mobile, I want the grid of 12 to be a horizontally-scrollable list where about 4.5 items can be seen at once, and tapping them has the same functionality.

How is something like this done?
 

grmlin

Member
Sure, make the list inline(-block), prevent line breaks with white-space: nowrap and let it scroll with overflow. Works fine on modern mobile devices.
 

jokkir

Member
How do you link to external scripts/css on Vue.js?

I want to try using Material Design Components and/or Bootstrap with this app.
 

grmlin

Member
How do you link to external scripts/css on Vue.js?

I want to try using Material Design Components and/or Bootstrap with this app.

I'm not a vue user, but what do you mean? Don't you use some sort of task manager, webpack etc.? Install the dependency and import them.
 

Cptkrush

Member
I have an interesting question. I'm looking into moving toward functional JavaScript programming. Would learning Haskell be advised to sharpen up the concepts or should I just move forward with learning the concepts with JS?

I'm reading a bit of both in google searches, just wondering if any of you guys had an opinion either way. I'm currently leaning toward Haskell since it forces you to think that way because it is purely functional. But I also am trying to expedite finding a JS based job rather than my current ad agency Wordpress dev job.

Additional info: there is no custom work for me right now at my job, so my manager wants me to sharpen up my JS while we have downtime because he wants me to get out of Wordpress development and into front end engineering so I can find a better job. He's a great dude.
 

Ikuu

Had his dog run over by Blizzard's CEO
You could mess around with Elm, it compiles into JS so you can easily make web stuff.
 

Somnid

Member
I have an interesting question. I'm looking into moving toward functional JavaScript programming. Would learning Haskell be advised to sharpen up the concepts or should I just move forward with learning the concepts with JS?

I'm reading a bit of both in google searches, just wondering if any of you guys had an opinion either way. I'm currently leaning toward Haskell since it forces you to think that way because it is purely functional. But I also am trying to expedite finding a JS based job rather than my current ad agency Wordpress dev job.

Additional info: there is no custom work for me right now at my job, so my manager wants me to sharpen up my JS while we have downtime because he wants me to get out of Wordpress development and into front end engineering so I can find a better job. He's a great dude.

Haskell works. Elm might be a bit gentler and relevant.
 

grmlin

Member
I always wanted to give Elm a try, but it's already hard enough to find good react developers, I can't imagine this is any better with something like Elm. This is even more niche and I'm pretty sure all the agencies we work for would not allow us to use something like that.

:(
 

Zakalwe

Banned
Why people no use flexbox in 2017?

I was just given a design someone else made to refine, and they're still using text-align/line-height hacks to position shit in divs.

Someone think of the mobiles!

(I'm going to suggest I give a quick tutorial to the team I handled this for, I don't care if I get paid for it developer sanity is at stake!)
 

GHG

Gold Member
Why people no use flexbox in 2017?

I was just given a design someone else made to refine, and they're still using text-align/line-height hacks to position shit in divs.

Someone think of the mobiles!

(I'm going to suggest I give a quick tutorial to the team I handled this for, I don't care if I get paid for it developer sanity is at stake!)

Concern about not supporting legacy IE browsers and not being bothered to work in the fallbacks would be my guess.
 

GHG

Gold Member
At this point, those users should be used to web sites looking like shit for them :p

The problem is some clients insist on it. Then there comes the moment when you realise it's because their work computers are running IE 7/8/9 and their internal IT department are a bunch of horribly incompetent old fogies.

At this point I'm strongly considering saying no to those clients and explaining nicely that it's for their protection. Microsoft no longer support those browsers so why should I? Why are you leaving yourself open to security risks? Etc.

It's infuriating.
 

Lister

Banned
The problem is some clients insist on it. Then there comes the moment when you realise it's because their work computers are running IE 7/8/9 and their internal IT department are a bunch of horribly incompetent old fogies.

At this point I'm strongly considering saying no to those clients and explaining nicely that it's for their protection. Microsoft no longer support those browsers so why should I? Why are you leaving yourself open to security risks? Etc.

It's infuriating.

Oh believe me, I'm happy I only have to dela with our own intranet applications. I get to say: Chrome only.

Feels good.
 

Zakalwe

Banned
Concern about not supporting legacy IE browsers and not being bothered to work in the fallbacks would be my guess.

They're a modern start-up, no legacy software.

I'd not have taken the job if it had been the latter, too much of a headache.
 

grmlin

Member
I'm always surprised how many developers I know don't use it at all, and basically have no idea how flexbox works.

IE 10/11 bugs can be pretty painful though, so keep that in mind using it.

Anyway, there is no world without it for me anymore. If I have to support some legacy browsers, they will get some fallback.
 

5olid_5nake

Member
Sooooo, any tips on how do I make this with bootstrap? While keeping the responsiveness of course:

gpodfP.png
 
The problem is some clients insist on it. Then there comes the moment when you realise it's because their work computers are running IE 7/8/9 and their internal IT department are a bunch of horribly incompetent old fogies.

At this point I'm strongly considering saying no to those clients and explaining nicely that it's for their protection. Microsoft no longer support those browsers so why should I? Why are you leaving yourself open to security risks? Etc.

It's infuriating.

Well, it could also be mandated by law. :p
 

5olid_5nake

Member
Lol.

Solved it, just added div inside another div with the following css:

display: inline-block;
width: 30%;
padding: 10px;
border-top: 2px solid #333;
float: right;
margin: 0px 0px 5px 15px;

Result:

Rf9Pw6.png
 

Earendil

Member
Hey guys. Are there any good forums out there dedicated to web development, and specifically SPA frameworks like Angular or React? My client side experience the last several years has all been with Angular/Angular2, but I'm beginning to wonder if I should get some experience with React. Up until the job I have now, I have always been Full Stack, so I'm a little out of the loop with Node/NPM and some of the other popular frameworks out there.

This thread is a good resource, but I was hoping for something a bit more targeted. Thanks.
 
Hey guys. Are there any good forums out there dedicated to web development, and specifically SPA frameworks like Angular or React? My client side experience the last several years has all been with Angular/Angular2, but I'm beginning to wonder if I should get some experience with React. Up until the job I have now, I have always been Full Stack, so I'm a little out of the loop with Node/NPM and some of the other popular frameworks out there.

This thread is a good resource, but I was hoping for something a bit more targeted. Thanks.

For React, Reactiflux is most likely the biggest community https://www.reactiflux.com/
 
I am on holiday, so I made Sheriff generator, a React App for creating the hottest emoji Sheriff memes.

https://howdy.petetnt.xyz

The source is at GitHub, if you want to see a pretty normal stack we work with. It's build with React, styled with Styled Components and application state is managed with Freactal (usually with Redux, but I wanted to play with Freactal again).
 
The problem is some clients insist on it. Then there comes the moment when you realise it's because their work computers are running IE 7/8/9 and their internal IT department are a bunch of horribly incompetent old fogies.

At this point I'm strongly considering saying no to those clients and explaining nicely that it's for their protection. Microsoft no longer support those browsers so why should I? Why are you leaving yourself open to security risks? Etc.

It's infuriating.

I agree saying no to them. It's not worth it. If you have to support IE7/8 you can't have a modern website. IE9 mostly has enough polyfills to get mostly feature complete so it's achievable with bugs.

If you have to keep the client, you should come up with an explanation for 'graceful degredation,' basically, the core functionality will be there... IE8 users will still be able to use the site, but it won't function 1:1 with modern browsers and will look very wrong. You can explain that their designs are not achievable in old browsers without major compromises, or far more time (e.g., 450 hours or something ridiculous that they wouldn't pay..... and if they do pay... make it work)

Oh nm this is a hypothetical
 

Kieli

Member
I'm working with Javascript, and the following code isn't doing what I want it to do:

Code:
function kebabToSnake(str) {
	for (var i = 0; i < str.length; i++) {
		if (str[i] === "-") {
			str[i] = "_";
		}
	}

	return str;
}

Namely, I wish to replace all instances of "-" in the string with "_" and return the string.

However, it seems as if the code doesn't do anything. Does JS not understand the following piece of code: str = "_"?

Edit: Found out the answer. Strings in JS are immutable; therefore I need to create a new string with the replaced characters and then return it. Well, that's annoying. :\
 

YoungFa

Member
I'm working with Javascript, and the following code isn't doing what I want it to do:

Code:
function kebabToSnake(str) {
	for (var i = 0; i < str.length; i++) {
		if (str[i] === "-") {
			str[i] = "_";
		}
	}

	return str;
}

Namely, I wish to replace all instances of "-" in the string with "_" and return the string.

However, it seems as if the code doesn't do anything. Does JS not understand the following piece of code: str = "_"?

Edit: Found out the answer. Strings in JS are immutable; therefore I need to create a new string with the replaced characters and then return it. Well, that's annoying. :

Unless its for some class assignment, this might be relvant for youx string.replace()
 

Somnid

Member
Edit: Found out the answer. Strings in JS are immutable; therefore I need to create a new string with the replaced characters and then return it. Well, that's annoying. :\

Not annoying, you're just going about it the wrong way because there are built-in ways to do what you want. In most cases you should avoid mutating anything.

Code:
function kebabToSnake(text){
   return text.replace(/-/g, "_");
}

Do note the use of a regex instead of a string for the first argument in replace. A common gotcha is that a string only replaces the first occurrence, you need a global regex.
 
Not annoying, you're just going about it the wrong way because there are built-in ways to do what you want. In most cases you should avoid mutating anything.

Code:
function kebabToSnake(text){
   return kebab.replace(/-/g, "_");
}

Do note the use of a regex instead of a string for the first argument in replace. A common gotcha is that a string only replaces the first occurrence, you need a global regex.

Exactly! (there's a small typo where return kebab should be return text in the example).
 

Lister

Banned
Mutation is an abomination unto the lord, so sayeth the wise alondo.

As an aside:

Is anyone working on any small scale/fun/what have you open source projects that wouldn't mind someone helping out?

I want to increase my open source footprint for job seeking purposes, and I want to learn more! Lots more to learn, always and I so rarely get to collaborate :(
 
Top Bottom