Programming

Cannot read property '1' of 'null'?

Learn Programming - Thu, 01/17/2019 - 23:24

The goal is to style the children elements of the 'section' container that the 'li' elements are in. But the error message I'm getting is: "Cannot read property '1' of 'null'.

What am I missing in my JS code?

JS:

var section = document.querySelector('section'); var paragraphs = section.children; for (let i = 0; i < paragraphs.length; i += 1) { paragraphs.style.color('blue'[i]); }

HTML:

<!DOCTYPE html> <html> <head> <title>Child Traversal</title> </head> <body> <section> <p>This is the first paragraph</p> <p>This is a slightly longer, second paragraph</p> <p>Shorter, last paragraph</p> </section> <footer> <p>&copy; 2019</p> </footer> <script src="app.js"></script> </body> </html>

submitted by /u/NotARestaurantLackey
[link] [comments]

Swift Community Podcast

Programming - Thu, 01/17/2019 - 23:13
Categories: Programming

Recursion practice problem "Drill, Baby, Drill!" help

Learn Programming - Thu, 01/17/2019 - 22:59

I'm trying to improve with solving recursion problems. I found this problem set online and am not sure how to continue with Problem 3 (Drill, Baby, Drill!). The class the problem set is from uses C++, but I'm more comfortable with Python.

Here's my set up so far (very little done with the actual problem solving part):

import math import collections drillSites = [(0,0), (6,0), (3,3), (0,6), (6,6)] def get_distance(tup1, tup2): x = tup1[0] - tup2[0] y = tup1[1] - tup2[1] dist = float(math.sqrt(x**2 + y**2)) return dist def list_distance(lst): distance = 0 for i in range(0, len(lst)-1): distance += get_distance(lst[i], lst[i+1]) # add distance between last point and first point distance += get_distance(lst[0], lst[-1]) return distance def bestDrillRouteFor(points_list, optimal_list): if len(points) == 0: return optimal_list else: for i in range(0, len(points_list)): chosen_point = points_list[i] # distance for if A is picked points_list = points_list.pop(i) optimal_list.append(chosen_point) dist1 = list_distance(bestDrillRoutesFor(points_list, optimal_list)) # distance for if A is not picked optimal_list.pop() points_list.insert(i, chosen_point) dist2 = list_distance(bestDrillRoutesFor(points_list, optimal_list)) # return shortest of the two return min(dist1, dist2)

So my plan is to go through all the permutations of the `drill_sites` points and then get the `list_distance` of them. I am hoping to return the list of the shortest distance. This function is clearly not right as right now I'm just returning a numeric value instead of a list in the recursive case. But is this permutation idea the right line of thinking at all? Can anyone please provide some direction?

submitted by /u/abasabada
[link] [comments]

MVC- What is Model?

Learn Programming - Thu, 01/17/2019 - 22:51

Programming in java. Learning to use multiple classes to make my code more "clean". Someone recommended me MVC; I love it. I think I'm having trouble understanding what model means. Please correct me if I'm wrong.

Let's say we have 3 buttons on a panel.

Model would define it like, new JButton startButton = JButton(); But obviously define panel to but the button on and a window to add the panel to.

View would display the button on the panel on the window.

Controller would let the user press the button to go from the start menu to the next screen, and so the cycle continues.

submitted by /u/Zillakazi
[link] [comments]

[any] how to deal with guard clause obviating the need for an else?

Learn Programming - Thu, 01/17/2019 - 22:43

I'm a big fan of exit guards. That is, something like this at the beginning of a function:

if (in != a) and (in != b) { return; } ...

However, I then often encounter a pattern like this, later on in the function:

if (in == a) { some stuff } else if (in == b) { other stuff }

Now, although I haven't quite drunk the kool-aid that every if should have an else, I do think that every else if should have an else. Except— I can't think of anything appropriate to put in an else except for die "ur processor is broken". How can I restructure my code to avoid this difficulty?

submitted by /u/Elronnd
[link] [comments]

16 year old beginner looking for advice on what to learn and what resources to use.

Learn Programming - Thu, 01/17/2019 - 22:32

16 years old, recently got very interested in programming. I've watched some YouTube guides and practiced writing HTML and python so far. I really want to grind hard for 100+ hours in my free time and hone this skill, and possibly pursue computer science in university. What kind of study plan would you advise for someone in my position? I'd love to hear about useful websites or videos.

Thanks!

submitted by /u/saudiarabian14
[link] [comments]

Confusion regarding relationship between bash on Windows and Windows Subsystem for Linux

Learn Programming - Thu, 01/17/2019 - 22:15

I have WSL active on my Windows PC. What I'm curious about the basics of how the subsystem is installed on the OS. When I activate WSL, is a version of Ubuntu installed in Windows? Furthermore, what's the difference between going in the Windows terminal and typing "bash" to run a bash terminal vs. running the application called "Bash on Ubuntu on Windows"? I'm sorry if this seems a bit basic to ask, but WSL is a bit confusing for me. Also, if I install a terminal app like Hyper, and I change the preferences of the terminal to use bash by default, its simply using the WSL Ubuntu install to accomplish this, correct?

submitted by /u/sammito1
[link] [comments]

I just finished my first project ever: DnD Dice!

Learn Programming - Thu, 01/17/2019 - 22:01

Hey!

So I have been learning to code for about 3-4 weeks now, and I finally finished my first ever project! So I transferred into CS this semester (hence my only been coding for 3-4 weeks) and I left my DnD dice at home over break..

So, I decided to write a program in python that lets me roll d20, d20+d6, d20+d6(*2) or d20+d6+d8!

It's actually been really useful and I'm kinda proud of myself. I never thought I could do something like this haha.

submitted by /u/warriors7796
[link] [comments]

At what point should I move on from html/css?

Learn Programming - Thu, 01/17/2019 - 21:57

I've been dipping into html/css the last few days and kind of want to go further afield so I can work on projects which are actually interesting to me.

I kinda hate following tutorials on sites like freecodecamp because the information never sticks with me if I'm bored, so I've just been learning on the fly whilst making a basic website and I've really enjoyed figuring out problems for myself(with googles help). I'm not sure if I've progressed enough to move on from these languages to something like Javascript and wondering if I should just bite the bullet and try to tough out freecodecamp until I've completed all the criteria?

Also, I haven't decided whether I'm going to want to go down the front-end/back-end route, is Java a decent language to sit on until I've decided?

Thanks :)

submitted by /u/Stevieyeet
[link] [comments]

What is 0X supposed to really mean in front of hexadecimal numbers? Can someone tell me if I have this answer right?

Learn Programming - Thu, 01/17/2019 - 21:57

Which is the most significant digit in the hexadecimal number 0x8b2da150?

I got 8, because I remember my teacher saying that 0x really doesn't matter that much but I didn't understand why it doesn't matter and why we don't have to count it.

submitted by /u/juravenator99
[link] [comments]

Add and drag text boxes in browser

Learn Programming - Thu, 01/17/2019 - 21:49

Hi all. I'd like to build something like this: clicking in the browser will create an editable, resizable, draggable textbox at that coordinate. Whatever is entered will be saved. What would be the best approach to build something like this?

submitted by /u/Shami_V
[link] [comments]

Made a chrome extension in couple days!

Learn Programming - Thu, 01/17/2019 - 21:40

Hey guys, this is actually the first time I've ever experienced coding in JS, HTML, CSS, etc. Decided to make a cool little extension as a small side project. Its basically an audible tab manager to quickly manage those pesky audible tabs that always seem to be hidden away. Check it out!

https://chrome.google.com/webstore/detail/sound-found/hdboefheamcmgbcjaedogecdikoomkhi?hl=en-US

Let me know if anyone is interested in the resources and information I used while developing the extension. The chrome API is actually really cool and I highly recommend other fellow programmers to start off making simple chrome extensions as it helps give a good introduction to programming! Best thing about it is you can produce pretty cool things in such a short amount of time.

submitted by /u/mestagonis
[link] [comments]

Question for the Programmers of Reddit

Learn Programming - Thu, 01/17/2019 - 21:36

Hello computer literate people!

This is my first post on this sub, so please excuse any errors. I know absolutely NOTHING about programming.

I am the Operations Director of a small non-profit that is branching out our scope of business. I am interested in developing an online platform (system?) that can is for internal use only as sort of a filing system. Think patient filing system type thing. I do not want to use one of the many already built ones out there, I would like to either learn to do it, or hire a programmer to build it specifically for our company. I just need help understanding exactly what I am asking for if I shall go to a professional. I hope I am making sense here. What would such a thing be called? Our company has a website, of course. But I am looking for an online management system to kind of organize all of our documents for each "patient."

submitted by /u/missstrugglebus
[link] [comments]

Creating an algorithm from a flowchart

Learn Programming - Thu, 01/17/2019 - 21:32

Hi, I'm completely new to programming/coding. What I'm trying to do is create a PDF or other web page or document that will populate certain sections of information based on the answers in a flowchart of scenarios. I am trying to create personalized documents for participants in a program, but I'm unsure how to take it from the flowchart stage and determining the limitations and end points of the chains of logic to something that actually will populate a PDF or other document. Any suggestions either on how to do it or what sort of information I should be searching for? I don't really know the correct terms for anything so I haven't really had much luck in my research.

submitted by /u/lispenardstreet
[link] [comments]

How do you read your ebooks? (ie kindle, laptop, etc.)

Learn Programming - Thu, 01/17/2019 - 21:25

I prefer reading on paper, so I mostly buy books; however, some books are only available (or simply cheaper) as ebooks so I'm thinking of picking up a kindle or tablet.

So I'm just wondering, how do you guys read your ebooks?

submitted by /u/gnatbeetle
[link] [comments]

[API Fetching Help] For some reason I am unable to get the data out the api link I've been given.

Learn Programming - Thu, 01/17/2019 - 21:10

https://codepen.io/anon/pen/WLqeov

I keep getting the error:

index.html:1 Uncaught (in promise) SyntaxError: Unexpected token in JSON at position 2

You should know I am noob with API stuff and started learning JS about 1 month ago. So please be kind :).

I just want to be able to get access to the data. Once I do, I'm confident in my own skills to use it!

Sidenote: in the codepen, I obviously got rid of the api key I currently have. If you think it's necessary to have there for you to troubleshoot and help me, getting one is as easy as and free as going here and registering.

submitted by /u/01123581321AhFuckIt
[link] [comments]

Need help understanding a solution (JavaScript)

Learn Programming - Thu, 01/17/2019 - 21:04

Working my way through FreeCodeCamp, and I'm struggling with the Record Collection modify function, specifically understanding a line in this solution:

function updateRecords(id, prop, value) { if (prop === "tracks" && value !== "") { if(collection[id][prop]) { collection[id][prop].push(value); } else { collection[id][prop]=[value]; } } else if (value !== "") { collection[id][prop] = value; } else { delete collection[id][prop]; } return collection; }

specifically the first nested if statement (line 3):

if(collection[id][prop]) {

It was my understanding If statements had to be conditionals. Is this line saying If that property is true...? or something else?

Thanks!

submitted by /u/anewlens
[link] [comments]

Pages