Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 days ago.
This post was edited and submitted for review 2 days ago.
Improve this question
im trying to build small project .
<body>
<button class="btnCheck">Click Me</button>
<p class"randomNumber">Random Number:</p>
<p class"recentNumbers">Last Numbers:</p>
<script>
let randomNumber = Math.floor(Math.random() * 20 + 1)
const recentNumbers = document.querySelector(".recentNumbers");
const btnCheck = doucment.querySelector(".btnCheck");
let paraNumber = doucment.querySelector(".randomNumber");
btnCheck.addEventListener("click",function(){
paraNumber.textContent = randomNumber;
for(let i = 0; i < randomNumber.textContent[i]; i++){
recentNumbers.textContent = randomNumber.textContet[i]'
})
</script>
// 2nd method :
randomArr = [];
recentNumbers.textContent = randomArr.push(randomNumber);
if (randomArr.length >= 5) {
randomArr.shift()
}
</script>
</body>
What I have been trying to do is : to show the last random numbers to limit to 4 recent numbers, everytime i click in the button,
when i pushed it to array it is not working and also it is creating new array everytime im clicking the button in the 2nd method
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
hello i'm work for question system i want to add many answers in a one question in a one value
html
<input id="an" placeholder="test" type="text"/><a id="wo" style="display:none;">done test</a><button id="bt">Submit</button>
javascript
const an = document.getElementById("an");
const bt = document.getElementById("bt");
bt.addEventListener("click", () => {
if (an.value.toLowerCase() === "test") { // I want create many value in here.
bt.style.display = "none";
an.style.display = "none";
document.getElementById("wo").style.display = "initial";
} else {
bt.innerText = "Wrong!"
bt.style.background = "red";
}
});
I hope this answer is what you are looking for:
You can make an array with your answers, and then check to see if the given answer is inside the array.
const array = ['test', 'test2', 'test3'];
if (array.includes(an.value.toLowerCase() ) )
...
Something else, you are missing a semicolon in your else { ... }.
bt.innerText = "Wrong!";
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 months ago.
Improve this question
I want to make one button 3-4 times clickable to change content. Same to this button: Go to this page ->
But I am able to make this button clickable only once.
You've already added the elements in an array, so a counter is the way to proceed from here:
var a = document.getElementById("box1")
var b = document.getElementById("box2")
var c = document.getElementById("box3")
var multy = [a,b,c];
var index = 0; // the counter
one(); // initialize the first render
function one(){
if (index >= multy.length) return; // bail if we've reached the last box
a.style.display = "none";
b.style.display = "none";
c.style.display = "none";
multy[index].style.display = "inline-block";
index++;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
im making a timetable that when opened gives me the zoom links to my classes and tells me what classes i have in the day.
function myFunction() {
var d = new Date();
var n = d.getDay()
document.getElementById("demo").innerHTML = n;
if (n == 1) {
document.writeln("Monday")
document.writeln("you have 2 classes today X and Y and the zoom links are: ...);
}
Don't use document.write, but append elements to some wrapper:
(function () {
var wrapper = document.getElementById('wrapper');
var links = {
'http://example.com': 'Example1',
'https://example.com': 'Example2'
};
for (link in links) {
tag = document.createElement('a');
tag.setAttribute('href', link);
tag.innerText = links[link];
wrapper.appendChild(tag);
}
})();
<div id="wrapper"></div>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have this array : const colorsarray = ['#F2387C', '#8A26A6', '#06ADBF', '#F2CE16']
And I have a list of item with unknown number of item, what I want to achieve is, I want to use these colors as a background color of item, but I want the colors to stay in order.
Example
Item 1 => bg:#F2387C
Item 2 => bg:#8A26A6
Item 3 => bg:#06ADBF
Item 4 => bg:#F2CE16
Item 5 => bg:#F2387C Go back to the first color
Item 6 => bg:#8A26A6 Go back to the second color
...
All I have right now is this code which chooses a color randomly if it could help :
var randcolor = colorsarray[Math.floor(Math.random() * colorsarray.length)];
Thanks for helping.
It's pretty simple, thanks to the % operator. Here's an example:
var elements = document.getElementsByClassName('yourclass');
var colors = ['#F2387C', '#8A26A6', '#06ADBF', '#F2CE16']
for(i = 0; i < elements.length; i++){
elements[i].style.backgroundColor = colors[i % colors.length]
}
Hope this helps!
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
So I'm trying to make two input fields calculate their value off one another. Here is my code so far:
function strToNumber (str) {
return Number(str.replace(/\D/g,''));
}
var number_2_calc;
var number_1 = strToNumber($("#number_1").val());
var number_2 = strToNumber($("#number_2").val());
$("#number_2").focusout(function(){
if(number_2 == 0) {
$("#number_2").val("");
} else {
number_2_calc = number_2 +(number_1 * 0.1);
$("#number_2").val(number_2_calc);
}
});
$("#number_1").focusout(function() {
if(number_2 == 0) {
$("#number_2").val("");
} else {
//not sure if necessary to create seperate vars here
var number_2_stored = strToNumber($("#number_1").val());
var number_1_stored =strToNumber($("#number_2").val());
number_2_calc = 0;
number_2_calc = number_2_stored +(number_1_stored * 0.1);
Math.round(number_2_calc).toFixed(2);
$("#number_2").val(number_2_calc);
}
});
So I'm trying to make it when you fill out either field then focus out it will change the input accordingly. This works fine when number_2 focuses out, but when you go back and change number_1 the values get messy. Probably just overlooking something simple, because this shouldn't be that difficult.
When you round the result, you need to assign back to "number_2_calc".
number_2_calc = Math.round(number_2_calc).toFixed(2);