I have been learning Javascript, for the following reasons:
1) It is the most obvious major programming language that I haven’t yet learned
2) It is very modern, providing functional programming paradigm (whereby global state is [in theory] eliminated, as all functions are “pure” [in other words, functions in the code are closer to maths functions, as in y = F(x) = (x*x), hence no global state!]; and other modern features such as readily providing anonymous functions/lambdas, Promises and Async/Await.
3) A lot of game engines use it now, Unity 3D, Cocos (Editor) and PlayCanvas to name a few.
4) It’s interesting.
So I have been learning from a course on Udemy:
“The Complete JavaScript Course 2019: Build Real Projects!”. It provides you materials and videos as you’d expect, but also exercises, which I have been doing, and am posting my solutions up here.
This is a simple two-player dice game, where you are meant to reach a target score of 100. You can roll the die, and add the number to your score, unless you roll a ‘1’, in which case control goes to the other player. You are allowed to ‘Hold’ your score however, which saves your score, although passes control over.
The exercises however were to add a second die, allow you to alter the maximum score, and to also pass on control if a double six was rolled. This is what I have implemented here (I have not just regurgitated the course materials).
You can find it at https://sourceforge.net/projects/javascript-dice-game/
Here is the code: