« first day (1496 days earlier)      last day (3446 days later) » 

12:00 AM
@Demorus yep
 
@dievardump // means or right? and why did you put {} in the array?
 
@Demorus // is a comment. || means or
and {} is an empty object. { trout: 'rotten' } is an object with a trout property
 
@Shmiddty aye, there's the rub.
 
@dievardump do we need empty objects?
 
Why not?
 
12:01 AM
@Demorus always
 
can we also add a number within: Math.random(10);
 
@Demorus javascript arrays are not strongly typed. However, we don't generally put mixed data types into them as a matter of practice
 
@Demorus if you want a box full of bonbons, you'll need an empty box to begin with.
 
oh ya true
I just cant imagine any of thosen things in action since I didnt try any real life examples yet except those console.log ones in codeecademy
 
@Demorus what languages do you have experience in?
 
12:04 AM
None it seems. Asking if // was a or is a pretty good example
 
let the man speak for himself, please
 
Let me conjecture and you read only his answer
 
@Shmiddty I know CSS3 and HTML fluently
 
@Demorus define fluently, please.
 
recently startet with jquery but wanted to expand my knowledge
@shmiddty by heart
 
12:06 AM
Show us some code / pages.
 
@Demorus In what regard? behavior? syntax?
 
@Shmiddty syntax and behavior
What do you want me to code in html and css?
 
Alright. You could say that a javascript array is kind of like a DIV. It will hold just about anything. It's not always the best tool for the job, but it does a pretty good job for most uses. Does that help your understanding?
 
@Shmiddty yes it does
That is exactly where I stopped at codeecademy since I wanted to practice in jsfiddle before I go on to arrays and while loops
 
Sounds like you just need to do some reading and experimenting. Come to us with questions when you understand a bit more. Cool?
 
12:12 AM
@Shmiddty indeed. thats why I did this jsfiddle.net/3jc7op45/15
im experimenting around
 
Alright. What were you looking to find out from that experiment?
 
    for (text = 8; text >=1; text-=4);
    document.getElementById('talk').innerHTML = text;
What did you expect to get from that? What behavior did you think it would have?
(so we know what you did not understand)
 
^ what he said
 
@Shmiddty just wanted to see how I make my newly acquired js knowledge interact with html elements. So in the example you see the idea is that "text" is display 4 times
but if the math value is below 50 steven is down, if above 50 he is happy
 
so you wanted one of the two strings to be displayed 4 times?
 
12:17 AM
First of all you mixed variables. You always use the same, for your random, for your content and for your loop
 
yes, or at least this is what thought for loops are for.
 
you are accessing and assigning to the same variable multiple times
 
in the for loop?
 
in the entire function
 
but there is no other way
if (text < 0.50) {
   text = "My name is Steven, I am down.";
} else if (text >= 0.50) {
   text = "My name is Steven, I am happy.";
}
 
12:18 AM
You can create more variables
 
I thought a variable of text would be enough for the task. Its cached or not?
 
There is no caching at this level
 
With the good paramaters, they are.
Here you said to your loop :
Begin with the value 8
Loop Until you are inf to 1.
After every loop, take out 4 fron your current value.

So your loop did :
loop1 : text = 8. Sup 1 ? YES. document.getElementById('talk').innerHTML = text; // here text = 8.
loop2: text = text - 4 = 4. Sup 1 ? YES. document.getElementById('talk').innerHTML = text; // here text = 4.
loop3: text = tex - 4 = 0. Sup 1 ? NO - STOP
 
HAMMERTIME!
HAMMERTIME!
 
!!undo
 
12:20 AM
@Shmiddty You do not have permission to use the command undo
 
for serious?
 
Denied!
 
Ah well. I rarely used my powers
 
hmm so what could be the use of the for loop in this context? new link jsfiddle.net/3jc7op45/19
 
with my super bad english I would translate your code with :

Set text to a random value between 0 and 1.
If text is inferior to 0.5 then set text = "My name is Steven, I am down.";
Else if text sup or egal to 0.5 set text = "My name is Steven, I am happy.";

Set text = 8;
Until Text is inferior than 1, write to text the content of the page, then substract 4 to text.
 
12:26 AM
ok so the for loop works it just outputs the entire thing as numbers is instead of the string text
 
because you told it, yes
an easy way to loop is:
 
so how would I convert a for loop number into a parameter or string
 
for( var i = 2; i > 0; i = i - 1) {
}
 
but the output would still be a number right?
 
It depends what yu output
if you output i yes it will, if you output text, and text contains a string, it will output a string
 
12:29 AM
so in this example without the "for" jsfiddle.net/3jc7op45/19 how would I make it output text?
 
var text = 'trout';
for( var i = 2; i > 0; i = i - 1) {
    document.body.innerHTML += text;
}
 
but I didnt output text, remember? text = X
 
boooo
 
@Demorus it outputed text. text was 8 then 4 than 0
 
var text = 'trout';
var output = '';
for( var i = 0; i < 2; i++ ) {
  output += text;
}
document.body.textContent = output;
 
12:32 AM
I thought the letter i can be any text. I thought i should be replaced with "text"
 
@Demorus a variable can be anything.
 
so whats up with for( var i = 0; i < 2; i++ ) {
output += text;
}
 
here he created a variable output with an empty string
 
rlemon added output text in {}
aha
 
then looped
to add 'trout' several times to output
 
12:33 AM
access the dom as little as possible.
don't update it in a loop like that when you can store the result and update once
 
@rlemon can you show me an example with my code?
 
he dos not understand loop man
 
The brackets({...}), create what is called a block. They are meant to group several lines of code. This is useful when you want to do something repeatedly or when you want to do something conditionally
 
don;t talk about the dom :/
 
don't w3schools him and start off with bad practices
 
12:35 AM
You might be able to relate it to a CSS counter, but it's a bit of a stretch
 
teacher 1 : "so you need to put the key in that thing and turn it to..."
teacher 2 : " and don't fuck with the freaking carburator"
 
w3schooling? XDDD
 
teacher 2 : "and don't step too much on the gas or you'll crash"
ftfy
 
Neeeh, with DOM you're already in the carburator thing
He is not even sure that you can put any variable name in a for loop
 
Im too stupid for this hehe
 
12:37 AM
I'm still not going to start off showing him innerHTML updates in a loop, when I can just as easily show him without and explain why
updating the page can be slow. if you can avoid updating in a loop when you can update once, do that.
 
I was using his code
 
... and I explained why
are we not here to learn?
 
I would begin by showing him how to make his code work
 
indeed
 
than explain him that to output he would have to use something else
 
12:39 AM
I haven't even looked at his code. I'm offering advice
 
I really need to know so that I can do go on to the next courses
 
He does not even understand the use of several variables
 
w/e - you help him. sorry for offering correct advise.
 
you want me to show him how to concatenate strings
 
wooa, guys xD
 
12:40 AM
no I'm done. you can have fun.
 
I would never use innerHTML in a for loop - but I chose to explain him how for loops work with his code to not completly lose him
 
basically I thought things like the example above are possible with for loops
actually I didnt know that you dont user innerHTML for a loop
 
*simplifie* stacktrace of rlemon code would be:
- text = 'trout', output = '';
- start loop : text = 'trout', output = '', i = 0;
- loop 1 : text = 'trout', output = 'trout', i = 1;
- loop 2 : text = 'trout', output = 'trouttrout', i = 2;
- stoop(hammertime) loop : text = 'trout', output = 'trouttrout'
- write output
 
since codeacademy didnt really have real examples on how to output strings to html
I just used console.log the entire time
 
because JavaScript is usually not that used to output strings to html
To do it properly you need to create elements etc... and codeAcademy won't show you that before you have the basics
You need to understand how things work before trying to do that thing.
scope, variables, types, loop, functions etc...
Than the DOM
 
12:44 AM
so I need to learn the entire js course
 
At least the base
 
Done all the previous. Im at "introduction to for loops and arrays"
I was abit tired of the console.log things since that is actually for debugging
 
I think it's weird that you're already there and still do things like :
var text = Math.random();
    if (text < 0.50) {
       text = "My name is Steven, I am down.";
    } else if (text >= 0.50) {
       text = "My name is Steven, I am happy.";
    }
 
why?
 
Because you're reusing a variable, with differemt types. I doubt it's something CodeAcademy would teach you
var rand = Math.random(),
    text = '';
    if (rand < 0.50) {
       text = "My name is Steven, I am down.";
    } else {
       text = "My name is Steven, I am happy.";
    }
1 : Math.random() give you a number, so the second condition is obviously >= 0.50
 
12:48 AM
the rock paper scissors lesson
var computerChoice = Math.random();

if (computerChoice <= 0.33) { computerChoice = "Rock";}
else if (computerChoice <= 0.66) { computerChoice = "Paper";}
else {computerChoice = "Scissors";}
 
That's the actual correction code ?
 
they repeat it. They do alot of repetition in if statements
what?
 
can you give me a link to that?
 
Why doesn't .filter change colors? jsfiddle.net/nbsgzmue/1
background-coloor
 
12:51 AM
If computerChoice is between 0 and 0.33, make computerChoice equal to "rock".
If computerChoice is between 0.34 and 0.66, make computerChoice equal to "paper".
If computerChoice is between 0.67 and 1, make computerChoice equal to "scissors".
 
they repeated computerChoice
 
Ok, than I doubt CodeAcademy is the right thing to learn.
 
so what do you do in order to not repeat things?
 
any idea on that? i think the jquery is claer
*clear
 
maybe they deliberately made it repeat so its easier to understand for newcomers
 
12:54 AM
    I would have :
var rand = Math.random(),
    computerChoice = 'Scissors';
    if (rand <= 0.33) {
        computerChoice = "Rock";
    }
    else if (rand <= 0.66) {
        computerChoice = "Paper";
    }
or with the last else, but setting Scissors to default is the same as else set it to Scissors
for me you do not use the same variable to pick a number and to set a content, they have different purpose, they need to be name and used in consequence
15 years ago, when program sizes were a problem, OK reusing the most possible the variables was something important.
Nowadays it's a bad practice
 
weird, the website opened up 2 years ago
so the guys behind it are bad
 
And they were in the top 50 ford website in 2013
I do not think they are bad, I think they messed up on this lesson, others are probably better
Or maybe they do not care about that, they might think they give you very basics during the xxxxx sessions and then you have to discover other things
But making you mixing variables when they teach you what a variable is, is weird
 
thats the entire code I wrote. Passed that lesson
 
@dievardump While I agree a separate variable is probably clearer, I don't think the CA code is terrible
 
so if my code really doesnt make sense and if they teach bad then I will stop
 
1:01 AM
HAMMERTIME!
 
@Retsam I did not say it's terrible. I said that teaching someone what a variable is, by mixing up variables contents is not a good way of teaching it.
It's suppose to be a website that teach you how to code, not some help you get once you have a problem
 
@Demorus so can we go back to your for loop. it's 2am here and I would love to finish what I was doing and then go to sleep
 
so in my above jsfiddle, what would be a better way of writing it?
sure, lets do it
 
cc @towc ^^^
 
1:03 AM
I won't read the who paper scissor code
 
ok
 
the loop, your code was :
var writing = function(){
    var text = Math.random();
    if (text < 0.50) {
       text = "My name is Steven, I am down.";
    } else if (text >= 0.50) {
       text = "My name is Steven, I am happy.";
    }
    for (text = 8; text >=1; text-=4);
    document.getElementById('talk').innerHTML = text;
 };
writing();
 
indeed
problem was how to actually convert those numbers into the random text
 
what you want is
(1) making a test 4 times, and writing the phrase
(2) testing one time and writing 4 times the same phrase?
 
Indeed, I think so yes
 
1:05 AM
hum, there is a or, you need to chose 1 or 2
 
should have been a xor :)
 
yes!
programming world is really confusing at times XD
option 2
 
oh ok
the for loop :
 
but if possible using the for loop. Just want to see how I can use that thing
 
for (text = 8; text >=1; text-=4);
document.getElementById('talk').innerHTML = text;
So here we have several problems :
 
1:07 AM
ok
 
you ; after your for loop, so here it won't do anything except loop
for (text = 8; text >=1; text-=4) {
    document.getElementById('talk').innerHTML = text;
}
Here what is between the brackets will be performed every loop
So now we will look at the for parameters
As I told you for(initialisation; condition; operation)
 
Man I hate it when designers claim to have designed around a grid and then completely ignore the ratios of the grid
 
@monners so true
That is really annoying
 
It's like You had ONE JOB!
 
@Demorus with the for(initialisation; condition; operation) you should notice that what you did is a little bit confusing
 
1:11 AM
alright
 
@monners Cripes, I have a terrible screenshot of exactly that from a few years ago
so sad
 
var i = null, length = 4;
for(i = 0; i < length; i = i + 1) {
    // content
}
or
for (var i = 0; i < 4; i = i + 1) {
    // content
}
 
you added i = i
 
@KendallFrey The best part is when you grab the dimensions from a psd and they're down to half-pixel values
 
what is the meaning of that particular part?
 
1:13 AM
it's the operation that is performed after every loop
 
@monners Now that you mention it, I seem to recall measurement to three decimal places
 
Here after every loop I increment i with 1
 
I am aware that its the operation but its the first time I encounter the i = i part. Usually I do i >= number or i === number etc
yes but isnt it enough to add i + 1
instead of i = i + 1
 
so the loop will be :
loop initialisation : i = 0
loop 1 : is i < 4 ? YES then execute the content - i = i + 1 (==1)
loop 2 : is i < 4 ? YES then execute the content - i = i + 1 (==2)
loop 3 : is i < 4 ? YES then execute the content - i = i + 1 (==3)
loop 4 : is i < 4 ? YES then execute the content - i = i + 1 (==4)
loop 4 : is i < 4 ? NO - then no more
@Demorus The operation part is not setting the value to i by itself, you have to explicitely tel it to change the value of i
in your code you used text -=4 which is the equivalent to text = text - 4
 
ah!
 
1:17 AM
I chose to use i = i + 1 because it's more reable and understandable than i-=1
 
so doing i = i +1 is the analog to i +=1
?
 
as doing i+=1 not i=+=1
 
oh ya, sorry. Corrected :D
for (var i = 0; i < 4; i = i + 1) {
// content
}
so this is what you showed me now
 
if instead of content you had console.log(i);
it would add to the console
0
1
2
3
 
so in content I add the innerHTML part right?
 
1:20 AM
for (var i = 0; i < 4; i = i + 1) {
    console.log(i);
}
try this in your dev tool
 
and then it outputs the text 4 times (0,1,2,3 for console.log)
 
so the bad practice, as in you code, would be to :
document.getElementById('talk').innerHTML = text;
But two things : it doesnt add to the HTML, it writes over it, so you won't see it 4 times, even if it writes 4 times, it will write over what was already writen
 
aha, I see
makes sense now
 
second this is a pretty bad thing to write like that
 
read a solution on stackoverflow
 
1:22 AM
as rlemon showed us, it's better to add that to a variable
and then at the end write only one time the variable to the html
 
wanted to know a equivalent to the console.log(X)
didnt I write that in a variable already? here the ne jsfiddle jsfiddle.net/3jc7op45/29
as you said, it works but overwrites the existing text 4 times
so i end up with only number 4
 
text is a variable but with your code you will write 4 times the variable in the HTML
It is better to write only one time in the HTML
 
how?
 
so the solution is to concatenate what you wanted to write, and write it when you're outside the loop
var output = '';
for (var i = 0; i < 4; i = i + 1) {
    output = output + text;
}
document.getElementById('talk').innerHTML = output;
here you will add your text to the variable output
 
concatenate was join strings right?
 
1:26 AM
@dievardump Do you avoid += and ++?
 
@copy for a beginner yeah.
 
Oh, makes sense
 
Im starting with javascript
so he made it more readable
 
Demorus imagine you want to give 4 bonbons to your child, in a box
 
it works!
still whats the magic here?
you have var output. The variable is empty
 
1:29 AM
you have two ways of doing it, fill the box and give it to him, or give him an empty box and then filling it with one at a time
 
so you gave an empty box
I see
 
arf
 
why output = output then?
 
nope sorry
output = output + text;
at first output == ''
then output === ('' + "My name is Steven, I am down.")
then output === ('' + "My name is Steven, I am down." + "My name is Steven, I am down.")
 
So apparently the world is $56 trillion in debt
 
1:33 AM
because you concatenate output
 
I understand but still only half
so basically output is an empty box. Then the empty box is equal to the variable text. This combination is a concatenation
 
Humpf
it's an empty string to which I concatenate strings
It's like when you write a sentence
 
then in innerHTML equals output . Since output = text it will display the text
 
at the beginning it's empty, you concatenate letters to create a long sentence
I just concatenate sentences together
As a html dev you should know the lorem ipsum
 
1:37 AM
ya
 
when your div is empty an you have some lorem ipsum in your clipboard and you ctrl+v several times
it put some lorem ipsum the one after the other
 
console.table is nice
 
same thing here with my output = output + text
 
the concept is really clear, I might just have some trouble understand why twice the output. I mean output = output. I understand the + text and everything else
 
ok let's try this
i = 0;
 
1:39 AM
why cant it be output + text
 
i = i + 1;
how much is i ?
 
2?
 
humpf
 
XDDD
wait 3
 
i = 0;
i = i + 1 = 0 + 1 = 1
 
1:41 AM
0h ok
ah!
 
for(i = 0; i < 100; i++)
can be compared to a Somme in math
 
So output first equals zero
 
output is a string
output = '';
output = output + text // '' + 'I am ....';
 
an empty string = empty string + text ....
 
You need to output = output + text
or it won't modify output
 
1:43 AM
I see, maybe im overcomplicating things :D
 
you can do ouptut + text
but it won't have any effect since you don't assign the resulting value to something
it's like doing
var i = 0;
1 + 3;
 
yes, my bad.
 
1+3 makes 4
but who cares since we do not use it
 
I thought we could have done output = + text
but that is invalid. You are right.
I understand now
 
output +=  text;
would work
 
1:45 AM
would have a different meaning
 
that would be the exact same thing
 
it would?
 
output = output + text
output += text
both do the same thing
 
+= means is more or equal to
oh nio sorry
it means increment
 
no it means "takes the current value and add xxx"
 
1:46 AM
got confused with >=
ok so we can write it like output = output + text or output += text
or I can take the current value and remove such as -=
 
`output = output + text` means assign to output "output + text"
which is the same thing as saying "add + text to the current value of output"
I am not sure -= will work with strings
 
I will try out in jsfiddle
 
It will give you NaN (Not A Number)
 
Because += with string will concatenate them. -= will try to susbtract and tell you they are not numbers
 
1:49 AM
but I assume I would have to adjust the for loop for it to work
 
(You should definitely use your dev tools instead of jsfiddle)
 
I use devtools just to edit css3 files or check for javascript errors
 
YOu're currently learning JavaScript, using the console in your devtool will do good
 
nice, im using chrome right now
 
then enter will execute the code. Shift + enter will go to the next line
 
1:51 AM
in the console section right?
 
Yep
 
One question, do you think I can learn this by following those courses ?
 
var output = '';
for (var i = 0; i < 4; i++) {
    output = output + ' ' + i;
}
console.log(output);
No idea, I did not follow those courses.
 
I find those videos and books are really for advanced users and I find the best way is to practice
what I like in codeacademy is that It not only explains but also has a code section where I can play around
 
Best way for everything it to practice. But theory is also mandatory. And you need to know how things works.
Reading about Algorithmie might be better to learn how things works.
 
1:56 AM
it covers alot of theory
just im abit confused now since you said they repeat the variables
since its bad practice
 
they reused
not repeat
 
I always thought reusing is good
 
the fact of putting a number in the variabe (Math.random)
 
variables are to be reused, or thats what I thought
 
when they have the same purpose
 

« first day (1496 days earlier)      last day (3446 days later) »