Skip to content

Commit b747bb6

Browse files
committed
Add functions to handle conversions
1 parent ff97c86 commit b747bb6

1 file changed

Lines changed: 24 additions & 10 deletions

File tree

app.js

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,30 @@
99
*/
1010

1111

12+
function getRandomDecimalNumber() {
13+
return Math.floor(Math.random() * 255);
14+
}
15+
16+
17+
function convertDecimalToBinary(decimalNumber) {
18+
return decimalNumber.toString(2).padStart(8, "0");
19+
}
20+
21+
22+
function convertBinaryToDecimal(binaryString) {
23+
return parseInt(binaryString, 2);
24+
}
25+
26+
27+
function convertDecimalToHexadecimal(decimalNumber) {
28+
return decimalNumber.toString(16).toUpperCase();
29+
}
30+
31+
32+
function convertHexadecimalToDecimal(hexadecimalString) {
33+
return parseInt(hexadecimalString, 16);
34+
}
35+
1236

1337
function App() {
1438
console.clear();
@@ -65,16 +89,6 @@ function App() {
6589
convertTo = event.target.value;
6690
console.info(`User updated 'convertTo': '${convertTo}'`);
6791
});
68-
69-
function getDecimalValue() {
70-
return Math.floor(Math.random() * 255);
71-
}
72-
73-
function decimalToBinary(decimalNumber) {} // TODO
74-
function decimalToHexadecimal(decimalNumber){} // TODO
75-
function binaryToDecimal(binaryString) {} // TODO
76-
function hexadecimalToDecimal(hexadecimalString) {} // TODO
77-
7892
}
7993

8094
// Start the app when the DOM is ready.

0 commit comments

Comments
 (0)