How can I change the order of the boxes [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed last year.
Improve this question
The order of the numbers in my box is as follows:
function boxNumbers(){
let boxes = document.querySelectorAll('.box')
boxes.forEach((box,i)=>{
if(String(i).length==1 || (String(i).length==2 && Number(String(i)[0]))%2==0){
//box.innerHTML = `${100-i}, i=${i}`
box.innerHTML = 100-i
}
else{
box.innerHTML = String(Number(`${9-Number(String(i)[0])}${String(i)[1]}`)+ 1)
}
})
}
how can I change it to look like this:

The way the pawns are moving, I think probably your board is not setup properly?
Shouldn't it be something like this:

Related

How to toggle class on and off depending if input field value [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
If the input contains a whitespace, add classList 'invalid', otherwise remove it.
function idValidationAttacher() {
const id = document.querySelector('#newid');
id.addEventListener('input', id.classList.toggle('invalid', ));
}
const id = document.getElementById('newid');
id.addEventListener("input", () => {
if(id.value.includes(" ")) {
// Add the code to show the error here.
}
});

How to Display each variable of for loop in a div tag using javascript? [closed]

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
How to Display each variable of for loop in a div tag using javascript? Using innerHTML i am only able to display the last variable of for loop
You can do as follows, but it is better to use lists.
Lists: https://developer.mozilla.org/pt-BR/docs/Web/HTML/Element/ul
const myDreams = ["Fly", "Be rich", "Go to the moon"];
const myDreamsDiv = document.querySelector("#myDreams");
//The secret here is to add a breakline(<br>) between each word.
myDreams.forEach(dream => myDreamsDiv.innerHTML += (dream + "<br>"));
<div id="myDreams"></div>

How do I check if the value of an input is a number using jQuery [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I need to check if the value of the input consists of numbers(0-9). Thanks for helping.
You can use Regular Expressions:
var result = /^[\d]+$/.test(yourInput);
Try to use isNumeric like this:
if($.isNumeric( input ) && parseInt(input)<10 && parseInt(input)>=0){
...
}

Find an element that has a text value of 0? [closed]

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 7 years ago.
Improve this question
I need to find an element that's text value is 0.
I do:
var d = $('.content').find('div');
if(d.text().length === 0){
//do something
}
Is there a way to put the above logic in the selector?
I've tried:
var d = $('.content').find('div:empty');
But no luck as the div may have other empty html tags in.
Use a filter
var elems = $('.content').find('div').filter(function() { return $(this).text() == 0 });

Print string with each letter having different color [closed]

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 8 years ago.
Improve this question
I have been wondering if I can print a string with each letter having a different color.
If I can do this can anybody tell me how ?
You can't directly set the color (or any part of the style) of a letter, you have first to wrap it in its own element so that you can style it. Here's an example :
var e = document.getElementById('s');
e.innerHTML = e.innerHTML.split('').map(function(l){
return '<span style="color:#'
+Math.floor(Math.random()*16777216).toString(16)
+'">'+l+'<span>'
}).join('');
Demonstration

Categories