6 Replies - 460 Views - Last Post: 29 November 2012 - 08:18 AM

#1 traverso85  Icon User is offline

  • New D.I.C Head

Reputation: -6
  • View blog
  • Posts: 36
  • Joined: 02-August 12

problem to recall var function

Posted 29 November 2012 - 07:59 AM

Hi, i'm Claudio form rome, hava a little problem to recall a var value of one function in other function....
have made this for check the time:
function orologio(){
	var ora=new Date()
	var or=ora.getHours()
	var mi=ora.getMinutes()
	var se=ora.getSeconds()
	//------Correzione sintassi orario------//
	if(or>12){
		or = or-12;	
	} if (or==0){
		or = 12;	
	}	
	//------Stampa per controllo orario-------//
	document.all["abc"].value=or+":"+mi+":"+se
}


and it work but when i recall some value in other function like this
$(function(){
	for(var i=1; i<=12; i++){
		var r = binario(i);
		if((r%2)==0){
			r = r.split("").reverse().join("");	
		}

		if(r == orologio(or)){
			var e = orologio(mi);
			e = (Math.floor(e/10))+1;
			$('#prova2').append(e.substr(e));	
		}

		$('#prova2').append(r + "<br/>");
		
	}
});


the program stop work when have to make control if value r = orologio(or).
How can i do this if that work?
Thanks Claudio

Is This A Good Question/Topic? 0
  • +

Replies To: problem to recall var function

#2 Kruithne  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 99
  • View blog
  • Posts: 439
  • Joined: 28-July 09

Re: problem to recall var function

Posted 29 November 2012 - 08:01 AM

Hello,

Your function orologio does not take any parameters, yet you appear to pass it a parameter that only exists inside the function itself, so is not actually accessible? I may be mistaken but I don't think you understand how functions work, either that or there is some code missing here.

EDIT: And as Dormilich said below, you lack any kind of return from the function too.

This post has been edited by Kruithne: 29 November 2012 - 08:06 AM

Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3390
  • View blog
  • Posts: 9,586
  • Joined: 08-June 10

Re: problem to recall var function

Posted 29 November 2012 - 08:04 AM

besides that, the orologio() function does not have a return value, yet you assign one (line #9).
Was This Post Helpful? 1
  • +
  • -

#4 traverso85  Icon User is offline

  • New D.I.C Head

Reputation: -6
  • View blog
  • Posts: 36
  • Joined: 02-August 12

Re: problem to recall var function

Posted 29 November 2012 - 08:10 AM

ithanks for your rapid reply... i need to read the value or, mi and se of part of code.... and use that in the second, how can i do? yes here miss some code in second part but it's code that don't have relationship with that....
Thanks more Claudio

View PostDormilich, on 29 November 2012 - 08:04 AM, said:

besides that, the orologio() function does not have a return value, yet you assign one (line #9).


than i have to insert a return value of any variable that i need?
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3390
  • View blog
  • Posts: 9,586
  • Joined: 08-June 10

Re: problem to recall var function

Posted 29 November 2012 - 08:13 AM

return them from the function.
function orologio(){
	var ora=new Date()
	var or=ora.getHours()
	var mi=ora.getMinutes()
	var se=ora.getSeconds()
	//------Correzione sintassi orario------//
	if(or>12){
		or = or-12;	
	} if (or==0){
		or = 12;	
	}	
	return {
		hour: or,
		min: mi,
		sec: se
	};
}
var t = orologio();
console.log(t.hour + ":" + t.min + ":" + t.sec);


PS. document.all is a IE-only extension. it will not work in other browsers. rather use standard DOM methods (like getElementById())
Was This Post Helpful? 1
  • +
  • -

#6 Kruithne  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 99
  • View blog
  • Posts: 439
  • Joined: 28-July 09

Re: problem to recall var function

Posted 29 November 2012 - 08:14 AM

Hello, here's a quick example of how to pass parameters into functions and return from them.
// Here we declare a function called myFunction which takes two parameters.
// Qui si dichiara una funzione denominata myFunction che prende due parametri.
function myFunction(myParameterOne, myParameterTwo)
{
	// Perform some logic, for this example we expect two numbers which we will add together.
	// Eseguire una logica, per questo esempio ci aspettiamo che due numeri che saranno aggiunti insieme.
	var answer = myParameterOne + myParameterTwo;
	
	// Return our answer variable
	// Ritorno nostra variabile risposta 
	return answer;
}

// Now, when we alert our function passing through five and sixteen, it will be twenty-one.
// Ora, quando si avverte la nostra funzione di passaggio attraverso cinque ei sedici anni, sarà 21.
alert(myFunction(5, 16));

Was This Post Helpful? 1
  • +
  • -

#7 traverso85  Icon User is offline

  • New D.I.C Head

Reputation: -6
  • View blog
  • Posts: 36
  • Joined: 02-August 12

Re: problem to recall var function

Posted 29 November 2012 - 08:18 AM

View PostDormilich, on 29 November 2012 - 08:13 AM, said:

return them from the function.
function orologio(){
	var ora=new Date()
	var or=ora.getHours()
	var mi=ora.getMinutes()
	var se=ora.getSeconds()
	//------Correzione sintassi orario------//
	if(or>12){
		or = or-12;	
	} if (or==0){
		or = 12;	
	}	
	return {
		hour: or,
		min: mi,
		sec: se
	};
}
var t = orologio();
console.log(t.hour + ":" + t.min + ":" + t.sec);


PS. document.all is a IE-only extension. it will not work in other browsers. rather use standard DOM methods (like getElementById())



thank you.... i go to try ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1