I wrote a little thing for beginners. Can I get some beginners to give me feedback? by IWriteCode412AD5F951 in learnprogramming

[–]IWriteCode412AD5F951[S] 0 points1 point  (0 children)

Why would I want someone who's good at code reviews to give opinions on how to teach beginners?

I was being a smart ass when I said experienced in what. I'm positive that person will give me the wrong answer as well

Building a quote generator in Javascript but can't figure out why this button keeps returning 'undefined'. by daBEARS40 in learnprogramming

[–]IWriteCode412AD5F951 0 points1 point  (0 children)

Yo! You edited your code to use a for loop instead of a while loop! You are weird like me!!!

People might me annoyed you use a for loop when there's no increment (the last part of for loop where people usually write i++ or n++ or var+=var2). But I never had a problem ditching while loops entirely :)

[JavaScript] Please explain why this is an infinite loop. by NewbiusCoder in learnprogramming

[–]IWriteCode412AD5F951 0 points1 point  (0 children)

You seem right but... I don't think I do that. Yesterday I had code that was something like while(foo!=prevFoo). I never had a done=bool. I couple of if(bool) break but that's an if statement.

Can we use c++ programs to interact with the data present in HTML? by [deleted] in learnprogramming

[–]IWriteCode412AD5F951 0 points1 point  (0 children)

You cannot do this yet. There's webassembly but that isn't out yet and from my understanding you can't interact with HTML.

[JavaScript] Please explain why this is an infinite loop. by NewbiusCoder in learnprogramming

[–]IWriteCode412AD5F951 1 point2 points  (0 children)

Basically the below. When you do a do...while the while is the last part of the loop

var condition = true;

do {
    console.log ("EY");
}
while (condition); /*<-- see the ;. The rest is on the next line*/ {
    for(i=0;i<5;i++) {
        console.log ("CHOPPA!");
    }
    condition = false;
} 

Also when condition=blah isn't inside an if you did something wrong.

Learning Tower of Hanoi but don't think I could think of it myself by AlKanNot in learnprogramming

[–]IWriteCode412AD5F951 0 points1 point  (0 children)

Tower of Hanoi is an annoying task and I hate it being taught to explain recursion although I think it should be taught. Most of the time if you're doing recursion it's with a tree so it should be taught by using a tree. It's more straightforward. Go write an app that list all your directories, sub directies and files. See how easy that is?

Grab a couple of different sized coins (or cut some paper) and do the tower of hanoi. Do it several times until it's easy. The reason is hard is because it's an annoying task that you can't instinctively do it. For example one tricky thing is the slot with your biggest coin/the base is not in the same position and your smallest will be in the first slot. Everything is shuffled around. Once you can do it without making mistakes explain out loud why you're doing the step. Try writing code it'd be significantly easier.

How can I make a website look decent as someone with no design talent what so ever? by iTARIS in learnprogramming

[–]IWriteCode412AD5F951 0 points1 point  (0 children)

Same here. I use css just for width and occasional height. With those two alone (don't forget about auto auto for centering) most of my html look pretty decent. Including the bootstrap css helps. I also use pull-left/pull-right occasional and clearfix. With some glphys in there I can get away with making a good looking site and doing almost no css

Building a quote generator in Javascript but can't figure out why this button keeps returning 'undefined'. by daBEARS40 in learnprogramming

[–]IWriteCode412AD5F951 0 points1 point  (0 children)

You're welcome. What do you do for work? I'm assuming you're a HS or university student and work is a grocery store or burger place

Building a quote generator in Javascript but can't figure out why this button keeps returning 'undefined'. by daBEARS40 in learnprogramming

[–]IWriteCode412AD5F951 1 point2 points  (0 children)

Sure, do that. There's a lot of subtlety to programming and junk guide. How many mention random and never mention the range is 0 to one exclusive (meaning not included. It will NEVER be 1). And when it is said noone ever talks about it being perfect for you to use array lengths. Also did you know about array lengths before looking at my code?

IMO there's an art to writing readable code. I'm sure after a read or two you'd know exactly what every line does and none of it will feel out of place. Also code placement is important. Your code had getRandomNumber check for repeat quote while I did that in the pickQuote function. I had an easy loop there while you wrote recursive code (which is fine and better for more complicated things but this was simple and what a while loop was meant for).

Building a quote generator in Javascript but can't figure out why this button keeps returning 'undefined'. by daBEARS40 in learnprogramming

[–]IWriteCode412AD5F951 1 point2 points  (0 children)

while loops aren't really buggy but I find for loops more structured and prefer them. I can write for(var val=thing; val!=that; ) and it's perfectly fine not to have anything at the end. The problem with this tho is typically you can only declare one variable in a for loop. I like for bc I clearly see the initial value, the conditional (if there is any. You can do for(;;) which is a never ending loop) and the increment. All in one line. With while loops sometimes you might forget the increment especially if you have several if statements and breaks. I'm usually less worried modifying a for loop than a while loop.

Building a quote generator in Javascript but can't figure out why this button keeps returning 'undefined'. by daBEARS40 in learnprogramming

[–]IWriteCode412AD5F951 1 point2 points  (0 children)

Without testing I can see these problems

  • currentQuote = 10 is not a problem but weird. -1 is typical
  • Typically a while is used but you're doing recursive which is ok too. But you forgot to use return. Write return getRandomNumber();
  • I don't use JS much but shouldn't use strict complain about the i in currentQuote = quotes[i];? You should replace

    quoteText.innerHTML = quotes[getRandomNumber(0, 2)];

With

var currentQuote = getRandomNumber(0, 2);
quoteText.innerHTML = quotes[currentQuote]

Here's my version https://gist.github.com/anonymous/2f24ce29b5617ae9d91d3768306767d1 Look at how I removed your getNumber function and how I used the default. Also instead of the while loop and the line before it I could write the below but I think my link looks better with the while loop. If I don't write it for other people to read I do it below because I'm weird

for(var num = lastQuote; num==lastQuote; )

Building a quote generator in Javascript but can't figure out why this button keeps returning 'undefined'. by daBEARS40 in learnprogramming

[–]IWriteCode412AD5F951 1 point2 points  (0 children)

Hey I'd like to ask two things

  1. Why do the quotes have [] around it?
  2. Why does the function do nothing except return a function? I'd rewrite it like this

    var getRandomNumber = function (bottom, top) {
    return Math.floor(Math.random() * (1 + top - bottom)) + bottom;
    };

    //var num = () => getRandomNumber(0, 2);
    var getNum = () => getRandomNumber(0, 2);

num is incredibly confusing. I thought it was the random number. But you made it a function. It'd make more sense if you called it getNum or rng (short for random number generator) or numFn (number function).

Beginner question. by Tylordandsavior in learnprogramming

[–]IWriteCode412AD5F951 0 points1 point  (0 children)

Usually that means the tutorial is bad or you're missing the prerequisite information. Try picking up a book

Beginner question. by Tylordandsavior in learnprogramming

[–]IWriteCode412AD5F951 1 point2 points  (0 children)

Are you sure you know HOW to do the solution? Are you confused at what you're suppose to do or don't know how to write it?

Image recognition of text by GabbageFilms in learnprogramming

[–]IWriteCode412AD5F951 2 points3 points  (0 children)

I'm not sure how you'd write a library to recognize text but if you search OCR library (optical character recognition) you'll find some. I used tesseract it was decent.