lesson #13 / html5, css, javascript tutorial, web programming [w/ subs]



00:00:01 – this is lesson #13 and I'm gonna show you more javascript using the Collatz conjecture,
00:00:05 – this is what we got, a textbox with a number and a button and when you click this button
00:00:11 – you get a series of numbers that seem pretty unpredictable, you can feed it any number
00:00:15 – – Collatz was a German mathematician who stumbled upon a very simple algorithm that turned out
00:00:22 – to be an extremely hard mathematical problem, I suggest you not to try to solve it, it says
00:00:27 – that you take a positive integer and if it's even you divide it by 2 and if it's odd you
00:00:33 – multiply it by 3 and add 1 and the conjecture says that you will eventually reach 1 in every
00:00:40 – case, this has not been proven yet – so when you click the button, we will call this function
00:00:46 – and first of all we clear the output for which we use the div here, then we take the value
00:00:53 – of the textbox and put it into variable n then we use a conditional statement which
00:01:01 – is very useful in programming, we say that if the value of n is less than 1 then we replace
00:01:07 – it with something else, here we make sure that the number that we feed into the algorithm
00:01:12 – is bigger than 1 or equal then we print it and then we have a cycle here – we check if
00:01:22 – the number is even by dividing it by 2 and check if its modulus is equal to zero because
00:01:29 – if so then it can be divided by 2, then we replace its value with something – we have
00:01:37 – another conditional branch here with a keyword else which says that if it's not even then
00:01:45 – we replace its value with something else which is 3 times n plus 1 then we print it – if
00:01:51 – the condition is not met then the cycle exits and continues interpretation – our program
00:01:59 – will end here because we don't have any more commands here so feel free to play with it,
00:02:04 – thanks for watching


Video Url:
http://youtu.be/EHQ1vxOvOrg

Comments

comments