How can i print a link within a document.write? [closed] - javascript

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>

Related

Javascript | last recent numbers [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 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

How I can Create many answer [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 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!";

Click the One Button Multiple times to change the text multi time [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 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++;
}

Why do elements from html to js file go as objects [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 1 year ago.
Improve this question
var toplama_islemi = (document.getElementById("toplama_islemi").style.display ="none");
var cıkarma_islemi = (document.getElementById("cıkarma_islemi").style.display ="none");
var carpma_islemi = (document.getElementById("carpma_islemi").style.display ="none");
var bolme_islemi = (document.getElementById("bolme_islemi").style.display ="none");
And why are there two equal signs here?
Those aren't comparisons. They're assignments. The styles are applied to the elements, and then the elements' style property values are assigned to variables.
Here's a demonstration.
setTimeout(function() {
var toplama_islemi = (document.getElementById("toplama_islemi").style.display = "none");
var cıkarma_islemi = (document.getElementById("cıkarma_islemi").style.display = "none");
var carpma_islemi = (document.getElementById("carpma_islemi").style.display = "none");
var bolme_islemi = (document.getElementById("bolme_islemi").style.display = "none");
console.log({toplama_islemi, cıkarma_islemi, carpma_islemi, bolme_islemi});
}, 2000);
<p>Wait for it...</p>
<div id="toplama_islemi">toplama_islemi</div>
<div id="cıkarma_islemi">cıkarma_islemi</div>
<div id="carpma_islemi">carpma_islemi</div>
<div id="bolme_islemi">bolme_islemi</div>
Everything is an object in JavaScript (except primitive values). If you don't want the style property values returned, do the steps separately:
var toplama_islemi = document.getElementById("toplama_islemi");
toplama.style.display = "none";
Now the element is assigned to the variable instead.

JS Sorting an array of alphanumeric strings by ending numbers? [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
Can someone please show me how to sort this
var videos = ["https://example.net/download/7/video-104.mp4",
"https://example.net/download/7/video-105.mp4",
"https://example.net/download/7/video-106.mp4",
"https://example.net/download/7/video-108.mp4",
"https://example.net/download/7/video-110.mp4",
"https://example.net/download/7/video-112.mp4",
"https://example.net/download/7/video-114.mp4",
"https://example.net/download/8/video-107.mp4",
"https://example.net/download/8/video-109.mp4"]
into this
var videos = ["https://example.net/download/7/video-104.mp4",
"https://example.net/download/7/video-105.mp4",
"https://example.net/download/7/video-106.mp4",
"https://example.net/download/8/video-107.mp4",
"https://example.net/download/7/video-108.mp4",
"https://example.net/download/8/video-109.mp4",
"https://example.net/download/7/video-110.mp4",
"https://example.net/download/7/video-112.mp4",
"https://example.net/download/7/video-114.mp4"]
it should be sorted based on last numbers in string before .mp4 but it doesn't work
var videos = ["https://example.net/download/7/video-104.mp4",
"https://example.net/download/7/video-105.mp4",
"https://example.net/download/7/video-106.mp4",
"https://example.net/download/7/video-108.mp4",
"https://example.net/download/7/video-110.mp4",
"https://example.net/download/7/video-112.mp4",
"https://example.net/download/7/video-114.mp4",
"https://example.net/download/8/video-107.mp4",
"https://example.net/download/8/video-109.mp4"
]
videos.sort(function(a, b) {
var spix = a.split('-')[1];
a = parseInt(spix.split('.mp4')[0]);
var spixb = b.split('-')[1];
b = parseInt(spix.split('.mp4')[0]);
return a - b;
});
console.log(videos);
videos.sort((a,b) => a.split('-')[1].slice(0,-4) - b.split('-')[1].slice(0,-4));
console.log( videos)
Basically I'm just splitting it by the "-" then taking out the '.mp4' and sorting it
Your issue is with the defenition of variable b. You defined it incorrectly as b = parseInt(spix.split('.mp4')[0]); it should be b = parseInt(spixb.split('.mp4')[0]);
var videos = ["https://example.net/download/7/video-104.mp4",
"https://example.net/download/7/video-105.mp4",
"https://example.net/download/7/video-106.mp4",
"https://example.net/download/7/video-108.mp4",
"https://example.net/download/7/video-110.mp4",
"https://example.net/download/7/video-112.mp4",
"https://example.net/download/7/video-114.mp4",
"https://example.net/download/8/video-107.mp4",
"https://example.net/download/8/video-109.mp4"];
videos.sort(function (a, b) {
var spix = a.split('-')[1];
a = parseInt(spix.split('.mp4')[0]);
var spixb = b.split('-')[1];
b = parseInt(spixb.split('.mp4')[0]);
return a - b;
});
console.log(videos)

Categories

Resources