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

Related

Dynamic variable creation in a loop by queryselectorAll [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
with this code I managed to create a child to each of the elements of the Node list via QueryselctorAll but I need to retrieve the tille ((document.queryseletor(....).title) works but not dynamically...) of the parent div dynamically as a variable to enter it in the innerHTML of the child. Do you have an idea ?
function onloaddiv() {
for (const item of document.querySelectorAll('.mat_option')) {
divp = document.createElement("div");
var2 = document.querySelector(".mat_option").title;
divp.innerHTML= "" + var2;
item.append(divp);
}
}
From your description I'm not 100% sure what you'd like to achieve, but maybe this?
function onloaddiv() {
for (const item of document.querySelectorAll('.mat_option')) {
divp = document.createElement("div");
var2 = item.title;
divp.innerHTML= "" + var2;
item.append(divp);
}
}
You don't need to query selector once again, you already have item in your loop
function onloaddiv() {
for (const item of document.querySelectorAll('.mat_option')) {
divp = document.createElement("div");
divp.innerHTML = item.title;
item.append(divp);
}
}
It doesn't work "dynamically", as you say, because document.querySelector(...) returns only first element it could find.

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.

List all stripe charges in Nodejs [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 6 years ago.
Improve this question
We are migrating from Ruby to NodeJS and we essentially wanted a function like this in Node:
starting_after = nil
charges = []
while true
results = Stripe::Charge.all(limit: 100, starting_after: starting_after)
break if results.data.length == 0
charges = charges + results.data
starting_after = results.data.last.id
end
How should one go about implementing this in NodeJS?
var stripe = require("stripe")(
"sk_test_xxx"
);
function paginateCharges(last_id) {
// Define request parameters
var req_params = { limit: 3 };
if (last_id !== null) { req_params['starting_after'] = last_id; }
// Get events
stripe.charges.list(
req_params,
function(err, charges) {
// Do something with the returned values
for (i = 0; i < charges.data.length; i++){
console.log(charges.data[i].id);
}
// Check for more
if (charges.has_more) {
paginateCharges(charges["data"][charges["data"].length - 1].id);
}
}
)
}
paginateCharges(null);

Javascript calculations returning wrong 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 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);

Categories

Resources