Question:

I need help writing a javascript function!?

by  |  earlier

0 LIKES UnLike

I need to write a function, but have no idea where to begin here are the first two steps:

A global variable named customertype should be created outside of the functions. This variable will be initialized with a value (i.e. customertype = "direct" ) and will be used by the functions below.

A function named "changetype()". The function will change the customer type each time it is run. It should change "direct" to "advertising", "advertising" to "subscription" and "subscription" to "direct". It does NOT do all three at the same time, it would take three calls to the function to change the value of customertype three times. Here is how I suggest you do this:

Create a local variable named newtype at the top of the function by using the keyword 'var'

Use three javascript 'if' statements to examine customertype and assign a new value to the local variable newtype

After the 'if' statements, assign the value in newtype to the global variable customertype

An alert at the end of the function informing the user the customer type has change will be useful, especially if it shows the new value stored in customertype.

 Tags:

   Report

1 ANSWERS


  1. Here is some code:

    var customertype="direct"

    function changetype()

    {

    if(customertype=="direct")

    {

    customertype="advertising"

    }

    else if(customertype=="advertising")

    {

    customertype="subscription"

    }

    else if(customertype=="subscription")

    {

    customertype="direct"

    }

    alert("Variable 'customertype' now contains the value '"+customertype+"'.")

    }

    After you have the code on your page, you can call it using various events such as onClick, onMouseover, etc.

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions