Skip to content

Commit

Permalink
u
Browse files Browse the repository at this point in the history
  • Loading branch information
hadithmv committed Sep 17, 2024
1 parent d1e32b0 commit 9640753
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 4 deletions.
51 changes: 47 additions & 4 deletions page-uc/textEditor.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
gap: 10px;
margin-top: 10px;
/* */
direction: rtl;
/*direction: rtl;*/
}

.function-button,
Expand All @@ -158,12 +158,28 @@
.copy-button-lit,
.copy-button-other {
font-size: 22px;
direction: rtl;
/*direction: rtl;*/
}

.function-button {
font-size: 18px; /* 16 */
direction: ltr;
/*direction: ltr;*/
}

.buttonInput {
width: 60px;
padding: 5px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 14px;
text-align: center;
}

.input1 {
color: red;
}
.input2 {
color: blue;
}

@media (max-width: 768px) {
Expand Down Expand Up @@ -625,7 +641,34 @@
</button>

<!-- -->
<button id="fullscreen" class="function-button" title="mmm">
<button
id="randomNum"
class="function-button"
title="Generates a random number from 1-10 by default, or you can set a minimum and maximum range next to this button after it has been initially clicked"
>
Randm No 🔟
</button>
<input
id="RandNoMinInput"
type="number"
placeholder="Min"
class="buttonInput input1"
style="display: none"
/>
<input
id="RandNoMaxInput"
type="number"
placeholder="Max"
class="buttonInput input2"
style="display: none"
/>

<!-- -->
<button
id="fullscreen"
class="function-button"
title="Switches to fullscreen mode"
>
Fullscreen 🖥️
</button>
</div>
Expand Down
52 changes: 52 additions & 0 deletions page-uc/textEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,58 @@ when there is a ّ character that comes after an arabic character, the output s
});
//

/* generate a random number up to ten when this button is first clicked, also clicking this button should show two input boxes saying max and min respectively as placeholders, which lets the user input a custom range of values, within which, further clicks on the button will generate random numbers within the range of those given input numbers
the input boxes should not show before the button has been clicked
the textarea text should be replaced each time the button is clicked
*/

const RandNoMinInput = document.getElementById("RandNoMinInput");
const RandNoMaxInput = document.getElementById("RandNoMaxInput");

let minRange = 1;
let maxRange = 10;

function generateRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

document.getElementById("randomNum").addEventListener("click", () => {
if (RandNoMinInput.style.display === "none") {
// First click: show input fields and generate number
RandNoMinInput.style.display = "inline-block";
RandNoMaxInput.style.display = "inline-block";
RandNoMinInput.value = minRange;
RandNoMaxInput.value = maxRange;
} else {
// Subsequent clicks: update range from input fields
minRange = parseInt(RandNoMinInput.value) || 1;
maxRange = parseInt(RandNoMaxInput.value) || 10;

if (minRange > maxRange) {
[minRange, maxRange] = [maxRange, minRange]; // Swap if min > max
RandNoMinInput.value = minRange;
RandNoMaxInput.value = maxRange;
}
}

// Generate and display random number
const randomNum = generateRandomNumber(minRange, maxRange);
textArea.value = randomNum.toString();
updateStats(); // Assuming this function exists to update statistics
});

// Update range when input values change
RandNoMinInput.addEventListener("change", () => {
minRange = parseInt(RandNoMinInput.value) || 1;
});

RandNoMaxInput.addEventListener("change", () => {
maxRange = parseInt(RandNoMaxInput.value) || 10;
});
//

//
//

Expand Down

0 comments on commit 9640753

Please sign in to comment.