Show results of multiple prompt boxes using Javascript [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 8 years ago.
Improve this question
How to make multiple prompt boxes and sort their input alphabetically and then show on screen using JavaScript ?
Thanks

Sequentially
if you are talking about the almost obsolete native javascrtipt function prompt() then:
var array=[];questions=['A?','B?','C?'],current=0;
function q(question){
array.push(prompt(question,'write here')+' question number:'+current);
if(current<questions.length){
next()
}else{
array.sort()// needs a proper sort function
alert(array.join("\n"));
};
}
function next(){
q(questions[current++]);
}
next();
Demo
http://jsfiddle.net/c7GnX/

Related

How to check in javascript if a list contains any element? [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 check if a list is not empty?
if (serialNumbersList.Any()) //c# expression equivalent
{
// do stuff
}
In javascript there are no lists but arrays, and you can check their length property
if(serialNumberList.length > 0) {
// Do your stuff
}

How to iterate and append characters of an array by push [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 2 years ago.
Improve this question
var charArray=[a,b,c]
I want to have a new array as following:
var charArrayNew=[a, ab, abc]
Please suggest how to get the result of charArrayNew in ES6 Javascript.
You could do this:
const charArray=['a','b','c'];
const answer = charArray.map((_,i,ar)=>ar.slice(0,i+1).join(""));
console.log(answer);
// or, alternatively:
fn=(ar,res=[])=>(
ar.reduce((a,c)=>(res.push(a+=c),a),""),res );
console.log(fn(charArray))

How can I detect if user has successfully alerted a thing (I'm making an XSS game) [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
The page just echoes the user input using GET. I have no idea on what concept to apply to detect if the user has alerted something
The easiest approach would probably be to replace the alert method with your own.
const log = [];
alert = function(alert) {
return (value) => {
log.push(value);
alert(value);
};
}(alert);
alert("Hello!");
console.log(log);

How to set variable of image src and use in javascript function? [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.
The community is reviewing whether to reopen this question as of 2 years ago.
Improve this question
So if i have some codes like this
If(sceneA){document.getElementById("divA").src="A.png";}
If(document.getElementById("divC")=="A.png"){document.getElementById("divB").src="B.png";}//And alot of codes here
How can I use a var to shorten strings like
document.getElementById("divA").src="A.png"
document.getElementById("divB").src="B.png"
so i can use them both inside (IF) and {function}
As they have to repeat quite a few times in the codes.
Thanks alot!
That's exactly what functions are for.
Define a function for repeating blocks of code as follows:
function setSrc(divName, imgName){
document.getElementById("div"+divName).src = imgName+".png";
}
function srcEquals(divName, imgName){
return (document.getElementById("div"+divName).src == imgName+".png");
}
Then you can replace your code with this:
if(sceneA){setSrc("A","A");}
if(srcEquals("C", "A")){setSrc("B","B");}

Create buttons dynamically in a div from a javascript function [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
I have a function that returns the data from the sql...
I need to create buttons in a div called
divResult
here is my function
function retrieveData(transaction, results) {
for(var i = 0; i < results.rows.length; i++) {
var data = results.rows.item(i)['nome'];
alert(data);
}
}
There is a very good answer on how to create html elements using javascript here: Creating Dynamic button with click event in javascript.
...I would add this as a simple comment but I don't have enough street cred yet.

Categories

Resources