Introduction
In this lab, we will explore the basics of JavaScript programming language. The purpose of this lab is to provide a hands-on experience for beginners in JavaScript to learn and understand the fundamentals of programming concepts such as variables, data types, operators, and control statements. By the end of this lab, you will have a solid foundation in JavaScript programming and be able to create simple programs on your own.
Generating Random Hex Color Code in Terminal/SSH
To generate a random hexadecimal color code in Terminal/SSH, follow the steps below:
- Open the Terminal/SSH.
- Type
node. - Use the following code to generate a random 24-bit (6 * 4bits) hexadecimal number:
const randomHexColorCode = () => {
let n = (Math.random() * 0xfffff * 1000000).toString(16);
return "#" + n.slice(0, 6);
};
- To generate a random hex color code, call the function
randomHexColorCode().
Example:
randomHexColorCode(); // '#e34155'
This will generate a random hex color code that you can use in your coding projects.
Summary
Congratulations! You have completed the Random Hex Color Code lab. You can practice more labs in LabEx to improve your skills.