Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7943029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:09:07+00:00 2026-06-04T00:09:07+00:00

I have a series of functions that i am passing the same variable to,

  • 0

I have a series of functions that i am passing the same variable to, however i want this variable’s value to change dependent on the window height. Setting var X works fine, though when i remove it and attempt to designate its value through a conditional statement it doesnt read:

<script>

var viewportHeight = $(window).height();

$(function() {
  $(window).resize(function() {
    if (viewportHeight >= 600) {
         var X = 100;
       }
    if (viewportHeight < 600) {
         var X = 50;
       }
   });
});
</script>

This of course would be placed within the same script tags as the scripts im affecting, as i dont believe its possible to set a global var this way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:09:09+00:00Added an answer on June 4, 2026 at 12:09 am

    change the x variable to global, try like this

     var x; // global vairable 
    $(function() {
    
      $(window).resize(function() {
        if (viewportHeight >= 600) {
            x=100;
           }
        if (viewportHeight < 600) {
             X = 50;
           }
       });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a series of functions that are all designed to do the same
I have a series of functions that I want to have the following functionality.
I have a constructor that has a series of classes and functions within it
I have a series of tables that contain data I want to full text
I have a series of commands (calls to bash shell functions really) that compute
I'd like to create a a series of variable like follows that have settings
I have a ext series of functions attached to a onClick handler that appear
I have a question about design. I have a series of generic functions that
Let's assume I have a series of functions that work on a sequence, and
I have a function that makes a series of calls to sscanf() and then,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.