Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
C#
function myfunction() {
                                if (Ruwani==dformat){
                                var name = "Ruwani Wickramaarachchi";
                                var bday = "it's "+ name +"'s Birthday";
                                return dformat;}
                                else if(Daisy==dformat) {
                                var name = "Daisy Victor";
                                var bday = "it's "+ name +"'s Birthday";
                                return bday;}

                                <!-- return bday; -->
                                }

i have created a local server website which retrieve system date and compare with stored date.
so i want to compare dates and if dates correct
i want to display

C#
var name = "Ruwani Wickramaarachchi";
var bday = "it's "+ name +"'s Birthday";
return dformat;


first condition is working but second is not working. i think it's if condition issue.
i think its about else if code.

dformat contains =

C#
var d = new Date();
 var dformat = [d.getDate(),
 d.getMonth()+1,
 d.getFullYear()].join('/');


this reads system date.
and i stored some dates like this and it will compare with system date. if its correct it will give and message to the textbox.

var Ruwani= "27/6/2014";
var Daisy= "28/6/2014";
Posted
Updated 26-Jun-14 19:17pm
v3
Comments
SRS(The Coder) 27-Jun-14 1:09am    
Why you think this will be an if condition issue ?
First of all it is not understandable that from where Ruwani, Daisy, dformat are coming and what are those variables contain, please explain this with your expectations clearly, to give us a chance to help you in this regard.
Hemas Ilearn 27-Jun-14 1:21am    
i said because my if condition and i tried else condition. both are working. just else if only not working.

1 solution

Why don't you try like this

C#
function myfunction() {
                                if (Ruwani==dformat){
                                var name = "Ruwani Wickramaarachchi";
                                var bday = "it's "+ name +"'s Birthday";
                                return dformat;}
                                else {
                                var name = "Daisy Victor";
                                var bday = "it's "+ name +"'s Birthday";
                                return bday;}

                                <!-- return bday; -->
                                }
 
Share this answer
 
Comments
Hemas Ilearn 27-Jun-14 1:20am    
actually it's more than two conditions. so o have to use 40 persons b'day like this. for that i have to use 4o if conditions.

your code is working perfect. no doubt about that
thanks for that.
but i need to work with else if.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900