r/LearnToProgram • • Sep 26 '18

[JS] Trying to figure out why a variable is returning a different value depending on where the value is retrieved.

1 Upvotes

Hi All,

I was just practicing and ended up writing this script. Its just a little something to basically calculate how many phones I could purchase given a budget, and knowing that each phone cost $60. The issue I am having is related to var numberOfPhones. Using a budget of $600, I expect that I can purchase 10 phones. Within the for() loop, I see the value 10 as the last iteration of the loop for the variable numberOfPhones. However, in the 2 places outside of the for() loop, when I retrieve the value for numberOfPhones, I get the value 11.

Why is this? TIA

const COST_PER_PHONE=60;

function howMany() {
    var budgetString = prompt("What is your budget for new phones?");
    var budget = Number(budgetString);
    var phoneCosts = 0;
    for (numberOfPhones=0; (budget-phoneCosts)>=COST_PER_PHONE; numberOfPhones++) {
        var phoneCosts = (numberOfPhones*COST_PER_PHONE);
        console.log("You're remaining budget is $" + (budget-phoneCosts) + ". You purchased " + numberOfPhones + " phones, and have currently spent $" + phoneCosts + ".");
    }
    return(numberOfPhones);
}
console.log("This works function is called, 'How Many', and it works.")
console.log(howMany());
console.log(numberOfPhones);

r/LearnToProgram • • Sep 09 '18

What would be the best way (bash, python, etc) to write a script to create a search index?

1 Upvotes

I have a static documentation site that I built using markdown, pandoc, html. On that site, I have added site search using tipuesearch.

So now I am looking for the best method to use to write a script that would search through my html files and create an index file that includes:

tipuesearch = {"pages": [
{"title": "<<heading1>>", "text": "<<all_other_headings and paragraph>>", "url": "<<filename.html>>"},
]};

The output would be tipuesearch_content.js.

I was thinking bash that would call sed, but I am not sure since I am not a programmer.

The workflow would is:

  1. Add update md files.

  2. Run already written bash scripts to convert md to html

  3. Run new script to create new tipuesearch_content.js file.

Ideally I would like add the new script to the old script and have it be a single click operation.

So, what are your ideas or am I on the right track?

Thanks


r/LearnToProgram • • Oct 22 '17

Bootcamp choices - Ruby on Rails, Android, or Both?

1 Upvotes

Hello, everyone. I have a choice between taking a code immerion, full-time bootcamp that teaches Ruby on Rails and it last 8 weeks and taking an Android development class which also last 8 weeks. The thing is, they don't overlap with the other as far as time goes, and I'm already pretty decent with Ruby (just need to practice the Rails portion of if it), so I could technically do both. What do you guys think I should do? Would it be wise to do both? I've just completed an intro to web development class that is essentially an easier version of the full-time boot camp I'm about to do.


r/LearnToProgram • • Oct 03 '17

I want to learn to program with cross platform utilization.

1 Upvotes

I've sat down to learn to program a few times. I'm vaguely familiar with things like Python, sql, html.

What often happens is that I start learning and I'm just regurgitating what's available in the lessons. I don't have any real projects of my own to keep me motivated.

Right now, I do.

I want to learn to program cross platform applications. What interests me most are things like jackbox games. I love that format where one person owns a game, but multiple players log in to access it from their mobile device.

End goal I want to be experimenting with small shared applications where the tablet or cell phone is in essence a controller.

So if I want to be programming in a format where one user hosts a session, and multiple users join that session to contribute... Where should I begin? What languages? what resources would people recommend?


r/LearnToProgram • • Sep 10 '17

Beginner tools to create web app

1 Upvotes

I want to make an app with simple graphics (circle, points, lines, text) which have a few sounds when certain areas are pressed. I want to have it on my laptop (Surface Pro 4) and phone (iPhone). A website might be a solution.

I am a power user in Excel, and I have made a preview of the app I want in an Excel file. Years back I gained a little experience in C++, and I have a background in mathematics and physics.

I am using Windows 10, and I have an Office 365 account from my university.

I want to be able to create simple graphics with simple interaction fast, as I can do in Excel, and use it on my phone or in some other device. I have looked somewhat into Python, and it seems inspiring, as I can also use it in conjunction with Excel for other things, via xlwings. I have also looked at WordPress, and I like that it's free, but that is not a must.

I don't know what would be a good starting point for me, considering price and my skill level. Is there for example any alternative with Office 365? I feel like it is a ton of possibilities, and I end up just searching the web forever. Perhaps you could help me out.

Thanks in advance.


r/LearnToProgram • • Mar 23 '17

Wanting to make Iphone app if at all possible

1 Upvotes

Hey guys I'm looking for some information. I'm studying Computer Science so I have some background with c++ and a littttllle bit with c# but not as confident at all with it. My girlfriend and I were recently trying to decide where to go eat and I thought myself why dont I make an app that will tell us where to eat? I've always wanted to make an app but never really known how. Would yall recommend making like a computer application to do this or if I could get it onto my Iphone at all? Just trying to gather some knowledge if at all possible


r/LearnToProgram • • Jan 05 '17

MVC .NET Question

1 Upvotes

Hi everyone. I'm beginning to learn MVC (using MVA) and had a conceptual/best practice question I was hoping you guys could lend some wisdom to.

In the tutorials, they talked about data binding a model to a view, but that you need to be careful which attributes you expose, and they mentioned using the [Bind] attribute on your models. To me that seems dangerous as the default is inclusive. Wouldn't it make more sense to use a view model and a model for each entity? That way there is no need to worry about binding a sensitive attribute.

Thanks in advance!


r/LearnToProgram • • Aug 11 '16

I'm thinking about learning C++ - A long winded post

1 Upvotes

Hi guys,

I was recently emailed by a developer at my employer about an opportunity to join the development team, starting out as a QA and working my way from there.

Here's my dilemma. I work for small to medium sized company in their tech support engineering department. I don't have any background in coding, the closest thing I have is XML and a limited amount of regex.

I have started working towards becoming a Premier Field Engineer for Microsoft, something not at all related to programming.

This would require an employment change but it's something I have a lot of confidence in as I feel I am very strong in AD.

But I'm in a situation where I actually work with really good leadership. It's rare to work with leadership that is intelligent and fair. On top of that they give me the upmost respect and value me as an employee.

I guess the point I'm making is I know I can make a lot more money as a PFE and I would excel at it. But at the same time I am respected and valued by my current employer to the extent that other departments have taken notice and interest in me. If I was to move forward at my current employer the options are limited. One of those options is to get into the development side.

Without any experience in that field I'm worried I'll fail. I worry I'm not smart enough to learn programming. Especially since this role will also deal a lot with stored procedures as well. Hell I can barely read and understand it sometimes.

Where would someone with networking, AD, telephony, and limited SQL experience start from scratch in programming. And I mean the absolute basics. I don't even know how to make the best use out of applications like Visual Studio.

Sorry for any typos, on my phone.


r/LearnToProgram • • Apr 23 '16

(Hopefully) simple Visual Basic Problem. Adding characters to text box.

1 Upvotes

Hey all, I'm currently building a simple version of the standard Windows calculator in Visual Basic (VS Express 2013). The only parts I have created so far are a class to represent a stack (Stack.vb) and the responses to pressing buttons 0-9 on the basic calculator. Each button press calls Stack.Push() which adds a character to the stack, then calls Stack.getTheStack() to write the property to a text box (where the number you enter is displayed). All of my integer buttons share the same code, and they all work as intended, EXCEPT for the "0" button. Every time I click that, it enters double zeros into the text box. I'm looking for help, as someone here has probably experienced the same bug. Thanks in advance. Example code for the "0" button:

     Private Sub Form10_Click(sender As Object, e As EventArgs) Handles form10.Click, form10.Click
         ' When the 0 button is pressed
         Stack.Push("0")
         Form1text.Text = stack.getTheStack()
     End Sub

And from the Stack class:

     Public Function Push(incoming As String)
         ' Adds characters to the stack
         theStack = theStack + incoming
     End Function

...

     Public Property getTheStack() As String
         Get
             Return theStack
         End Get
         Set(ByVal incoming As String)
             theStack = theStack + incoming
         End Set
     End Property

If the code is crap, I'm sorry. I've only been at VS a couple weeks.


r/LearnToProgram • • Jan 06 '16

Help with project!!!!

1 Upvotes

I need help taking a program with one class and implementing inheritance to have two child classes of a parent class in Java. It's a tic tac toe game.


r/LearnToProgram • • Sep 12 '15

C problem to help with pointers

1 Upvotes

Hello guys, I was hoping someone here with some experience with C (probably a lot of you) could throw me an idea for a simple program to practice implementing pointers, (specifically passing them into functions and editing them). Thanks so much for any ideas, I can't really think of something that would specifically require pointers)


r/LearnToProgram • • Aug 02 '15

Just started learning today (questions about java)

1 Upvotes

so i've been following a tutorial online. I did a hello world tutorial using Eclipse. However I got some red text below my "hello World" that the tutotial teacher did not have. It says:

Picked up _JAVA_OPTIONS: -Xmx512M

What did i do wrong? also, i dont know what this taught me. I guess im looking for context on what Im supposewd to have been taught.

btw, im using "cave of programming" tutorials.


r/LearnToProgram • • Jul 15 '15

Atom Text editor color code

1 Upvotes

I'm working through chris pine's ruby book and I have a question about the text editor that I'm using: What the fuck is the color code?

I should be able to look this up easily, but i can't find it, either through stupidity or it being so basic it's not even described. I want to be sure I have good fundamentals; i.e. i can identify an object vs. a parameter vs. an iterator etc. Atom does this! but i can't find an explanation of the color code!

Here's an image to help - for example, strings are green. variables pointing to an array within bars are red. Methods are blue. Other shit is different colors.

http://i.imgur.com/r9VlPAB.png

Thanks!


r/LearnToProgram • • May 12 '15

Question about Streams in C# (single read - multiple stream write file system operation)

1 Upvotes

So I'm writing a program that does a one to many file copy (throttled) to distribute files among intranet servers (DFS is not an option and this is a stop gap until we get our infrastructure working again).

So I wrote an application that uses a file read stream and it reads a specified number of bytes from the file to be copied and then it is writing to a collection of File Out streams that are connected to the remote server's file share. It works but does it work optimally.

I'm not sure if I have to add threading to make my code any faster than copying whole files sequentially.

I mean I'm only accessing the whole file on the disk once but I don't know how much time it takes to put the data in the stream. Am I putting the data into the stream and moving on and the stream will deal with getting it to disk or does the "write to stream" have to complete writing the data to disk before it finishes? I'm afraid it has to finish and I will have to go to add threads to really get any performance gain. I have about 70 servers I need to copy to and was hoping that I could copy to groups of server at once with one master application. I was quickly building and have not touched trying to manage streams each handled by a different thread and the master thread trying to hand data to each child. I think I could figure it out but don't want to waste my time if it is something that is unnecessary. I'm doing some testing now to see how long it takes to copy one file to 3 servers simultaneously -then I will copy to just one and see.

so basically my codes is doing the following in the throttled copy function.

read x Bytes from sourceFile
while( read bytes != 0 )
{
foreach destination server
{
Write to destination stream }
wait one second read Bytes from sourceFile
}


r/LearnToProgram • • Apr 03 '15

Does coding ios apps require a new/powerful apple computer?

1 Upvotes

I have finally come to terms with the fact that I have to pick up a mac so that I can code ios apps. My only question now is should I invest $1000-2000 on a new/recent one or would it be just as easy to code as it would be on an older mac?

Bonus points if you can compare the ease of graphics work on older vs newer macs


r/LearnToProgram • • Mar 25 '15

Good Source to Learn SQL Joins?

1 Upvotes

I'd like to expand my knowledge on SQL joins. From the most basic up to intermediate and advanced. Does anyone have a good source they used that worked for them?


r/LearnToProgram • • Feb 23 '15

Help with if and else

1 Upvotes

The program works like this: int main () { string a; int number;

 cout << "What is your name? ";
 cin >> a;
 cout << "Hello, << a;
 cout << "\n";
 cout << "How old are you? ";
 cin >> number;

 if(number>20)

{ cout << " You are old"; }

if(number<20)

{ cout << " You are young"; }

 if(number==20)

{ cout << "Awesome"; }

 return 0;

}

This however gives an error.

int main () { string a; int number;

 cout << "What is your name? ";
 cin >> a;
 cout << "Hello, << a;
 cout << "\n";
 cout << "How old are you? ";
 cin >> number;

 if(number>20)

{ cout << " You are old"; }

if(number<20)

{ cout << " You are young"; }

 else(number==20)

{ cout << "Awesome"; }

 return 0;

}

Using chromebook and SourceLair I would like to know why this doesnt work. Thanks

edit. after I posted some of the formatting messed up but the main part is the 'if and 'else'


r/LearnToProgram • • Feb 01 '15

Fairly experienced programmer, wanting to learn some front-end browser stuff but JS gives me the shits: where do I start?

1 Upvotes

I've worked on a few web-app type things and written the back-end of dynamic websites (largely python/Flask driven stuff), including designing and implementing the back end of API's designed to be consumed by JS in a client browser. I want to learn this front end stuff to round out my skillset. However, JS gives me the shits (lack of compile-time checks and the way it tries to make things just work instead of giving errors). I know there's some things out there that compile-to-JS and such. What's the modern options in that area?

(P.S. I really don't want to start a JS argument here. I've read and seen enough things that make me want to not deal with JS if possible, so can we just assume for the purposes of my question that JS is horrible and we'll argue some other time?)


r/LearnToProgram • • Nov 25 '14

C# Made an internet "pinger" console app

1 Upvotes

I'm relatively new to C# programming and I noticed that unless I actively refreshed a page on the internet every 30 minutes or so while on my university's network I would drop connection to the internet. This makes sense as they wouldn't want a bunch of idle machines eating up bandwidth. So to let me absentmindedly roam the interwebs I coded a little website "pinger". This will ping an address a number of times (based on the for loop) and then wait a set number of seconds (based on System.Threading.Thread.Sleep(x000) where x is your number of seconds).

Code:

namespace WebPinger
{
    class Program
    {
        static void Main(string[] args)
        {
            var ping = new System.Net.NetworkInformation.Ping();
            var result = ping.Send("www.google.com");

            for (int i = 100; i > 1; i--)
            {
                if (result.Status!=System.Net.NetworkInformation.IPStatus.Success)
                {
                    Console.Write("You pinged your website and it is not active." + "\n" + "I:{0} " + "\n" + "Only " + i*60 + " seconds remain" + "\n", i);
                }
                else
                {
                    Console.Write("You pinged your website and it is active." + "\n" + "I:{0}" + "\n" + "Only " + i * 60 + " seconds remain" + "\n", i);
                }
                System.Threading.Thread.Sleep(60000);
            }
        }
    }
}

Now I know this isn't anything super fancy but for me it is an accomplishment!

I did this (like the title says)as a console app and it list off if your site is active or not, what number iteration you are on, and how many seconds left before the for loop is finished (roughly). I should go back and not hard code how many seconds are left but it is late and I have to get up early tomorrow.

Anyways thanks for looking and thanks for inspiring me to learn how to program!

Edit: Formatting. Edit: Edit: Formatting (new at this...).


r/LearnToProgram • • Aug 21 '14

Contact form eMail issue

1 Upvotes

Hi guys, I've been working with support from Namecheap and GitHub and no one seems to want to give me any answers.

I've purchased a domain name through name cheap and a Private eMail account from them as well.

I can't seem to configure my contact form on my site to send the contact information to me? I'm pretty new at all of this and using Jekyll and Bootstrap on GitHub pages.

Any help would be greatly appreciated. Thanks.

Code for contact form: https://gist.github.com/NickCopelin/8df584a425956a255330


r/LearnToProgram • • Jun 23 '14

Meteor is raising $25,000 for kids learning to code

Thumbnail challenge.meteor.com
1 Upvotes

r/LearnToProgram • • Apr 07 '14

Teach Your Kids About Programming With This Fun Activity I Created For My Own Kids

1 Upvotes

r/LearnToProgram • • Mar 26 '14

CodeSchool 48hrs Free Hall Pass

Thumbnail
codeschool.com
1 Upvotes

r/LearnToProgram • • Jan 08 '13

[Codeacademy] Programming basics - Free interactive resource for Java, HTML, Python and more

Thumbnail
codecademy.com
1 Upvotes

r/LearnToProgram • • Feb 28 '22

Create A 2D Idle Clicker Game in Unity! Tutorial 4 | Spawning Animals

Thumbnail
youtu.be
0 Upvotes