473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Creating a function utilising an array

Hi

I am trying to create a function that adds to specific array, then
checks the array to determine whether to alert 'Yes' or 'No'.

Note this is a simplified version of the function I have created. This
function will be used with different arrays.
function change_value (check_value, array_name, array_number){

if (check_value == 'yes') {
array_name[array_number]='Y';
}
else{
delete array_name[array_number];
}

// check if there is a 'Y' anywhere in the array
if(array_name.length>0){
alert('Yes');
}
else{
alert('No');
}
return array_name;
}

Your help will be appreciated.

Regards

Bundy
Nov 20 '06 #1
3 1452
Lee
Bundy said:
>
Hi

I am trying to create a function that adds to specific array, then
checks the array to determine whether to alert 'Yes' or 'No'.

Note this is a simplified version of the function I have created. This
function will be used with different arrays.
function change_value (check_value, array_name, array_number){

if (check_value == 'yes') {
array_name[array_number]='Y';
}
else{
delete array_name[array_number];
}

// check if there is a 'Y' anywhere in the array
if(array_name.length>0){
alert('Yes');
}
else{
alert('No');
}
return array_name;
}

Your help will be appreciated.
What sort of help are you expecting? Since you haven't told
us what this simplified version is supposed to do or what it
is that it isn't doing that you want it to do, it's sort of
hard to know how to help.
--

Nov 20 '06 #2
In comp.lang.javascript message
<45***********************@unlimited.newshosting.c om>, Mon, 20 Nov 2006
16:31:51, Bundy <bi*******************@vfemail.netwrote:

Untested :

function change_value (check_value, array_name, array_number){

if (check_value == 'yes') {
array_name[array_number]='Y';
}
else{
delete array_name[array_number];
}

// check if there is a 'Y' anywhere in the array
//- if(array_name.length>0){
//+
for (var J=0; J<array_name.length ; J++) if (array_name[J]=="Y") break
if (J != array_name.length) {
//+
alert('Yes');
}
else{
alert('No');
}
return array_name;
}
or alert (J != array_name.length ? "aye" : "nay")

It's a good idea to read the newsgroup and its old FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
<URL:http://www.jibbering.com/faq/ Old RC FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Nov 21 '06 #3
aye it works.

Also, thanks for directing me to the FAQ, it answered many questions.

Regards

Bundy
Nov 21 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jeffrey Silverman | last post by:
Hi, all. I have a linked list. I need an algorithm to create a tree structure from that list. Basically, I want to turn this: $list = array( array( 'id' => 'A', 'parent_id' => null, 'value'...
20
by: svend | last post by:
I'm messing with some code here... Lets say I have this array: a1 = ; And I apply slice(0) on it, to create a copy: a2 = a1.slice(0); But this isn't a true copy. If I go a1 = 42, and then...
1
by: Rako | last post by:
My problem is: I want to create an index to any of the available picture-groups. This index is a table of thumbs with a scrollbar. If you click on the thumb, you get the full picture displayed. ...
2
by: Sugan | last post by:
Hi All, I have a peculiar kind of issue after converting VC and VB code from Visual studio 6.0 to Visual Studio 2005. We have the business logic in the VC code which uses the ATL framework...
0
by: Sugan | last post by:
Hi All, I have a peculiar kind of issue after converting VC and VB code from Visual studio 6.0 to Visual Studio 2005. We have the business logic in the VC code which uses the ATL framework...
8
by: ctiggerf | last post by:
I was hopeing someone could help me out here. Been stumped on this one all day. This function 1. Checks uploaded files. 2. Creates two resized images from each (a full size, and a...
17
Motoma
by: Motoma | last post by:
This article is cross posted from my personal blog. You can find the original article, in all its splendor, at http://motomastyle.com/creating-a-mysql-data-abstraction-layer-in-php/. Introduction:...
13
by: Justcallmedrago | last post by:
How would you declare and assign a variable inside a function THAT HAS THE NAME OF A PARAMETER YOU PASSED example: when you call createvariable("myvariable") it will declare the variable...
1
Airslash
by: Airslash | last post by:
Touchy subject I know, but I'm currently trying some stuff to understand Threads better in C++. I've read the Windows API documentation regarding Threads, and want to build a Thread class that can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.