Using a variable from one function in an other - think im missing something
<p>this is most probably simple but im struggling a little is it possible to do something like the below becasue its not alerting in the 2nd function.</p>

<pre><code>function func1() {
  var test = 5;
  var testAgain = 8;
}


function func3() {
  func1();
  alert(test);
}
</code></pre>

<p>edit:</p>

<p>Thank you all for your comments, however i cant seem to get it to work.</p>

<p>i below is the code i am trying to get this to work in</p>

<p>it does not seem to want to pass the vars from setImageReelWidth, and just alerts 0 when it gets to rotate = function () or $(".paging a").click(function (). so i click and it alerts 4 (which is correct) and then when it runs it twice again i just get 0</p>

<pre><code>var divWidth = 0;
var slideTotal = 0;
var divReelWidth = 0;


function setImageReelWidth() {
    var divWidth = $(".window").width();
    var slideTotal = $(".slide").size();
    var divReelWidth = divWidth * slideTotal;
    alert(slideTotal);
    //Adjust the image reel to its new size
    $(".image_reel").css({ 'width': divReelWidth });
}





$(document).ready(function () {
    ////////////////////////////  INITAL SET UP  /////////////////////////////////////////////

    //Get size of images, how many there are, then determin the size of the image reel.
    //var divWidth = $(".window").width();
    //var slideTotal = $(".slide").size();
    //var divReelWidth = divWidth * slideTotal;

    //Adjust the image reel to its new size
    //$(".image_reel").css({ 'width': divReelWidth });

    //set the initial not active state
    $('#prev').attr("class", "not_active");

    ////////////////////////////  SLIDER  /////////////////////////////////////////////

    //Paging + Slider Function
    rotate = function () {
        setImageReelWidth();
        alert(slideTotal);
        var triggerID = $slideNumber - 1; //Get number of times to slide
        var image_reelPosition = triggerID * divWidth; //Determines the distance the image reel needs to slide
        //sets the active on the next and prev
        if ($slideNumber == 1) {
            $('#prev').attr("class", "not_active")
            $('#next').attr("class", "active")
        }
        else if ($slideNumber == slideTotal) {
            $('#next').attr("class", "not_active");
            $('#prev').attr("class", "active");
        }
        else {
            $('#prev').attr("class", "active")
            $('#next').attr("class", "active")
        };
        //Slider Animation
        $(".image_reel").animate({
            left: -image_reelPosition
        }, 500);
    };

    ////////////////////////////  SLIDER CALLS  /////////////////////////////////////////////

    //click on numbers
    $(".paging a").click(function () {
        setImageReelWidth();
        alert(slideTotal);
        setImageReelWidth();
        $active = $(this); //Activate the clicked paging
        $slideNumber = $active.attr("rel");
        rotate(); //Trigger rotation immediately
        return false; //Prevent browser jump to link anchor
    });
</code></pre>
