Monday, July 30, 2018

How to Turn On or Off Bulb Using JavaScript ?

How to Turn ON or OFF bulb by using JavaScript ?  Now You are thinking about your Bed rooms bulb, How it can be possible ?  

#Hahahaha  It's not about your bed rooms bulb. Its a JavaScript coding tutorial or you can say JavaScript Tips & Tricks.

Let's see How you can Turn On or Off bulb by using JavaScript ?

Before go ahead one second,Let me tell you one thing, are you seriously thinking about your bad room's bulb ? No no this is not your rooms bulb its a programming bulb it can only understand by the most intelligent people in this world called PROGRAMMERs.

So Let's see 

How you can Turn On or Off your Programming Bulb by using JavaScript ?
Here are some basic JavaScript Syntax that will help you to understand basic about how to Turn On or Off bulb.

Syntax :
img src = image_name.png
In this JavaScript code you have two images of bulb that define the two states of the bulb, The first image or state is for Turn Off state and the second image or state is for Turn On state,

  Turn Off State  ;  img src = Turn_Off_Image.png                                                           Turn On State  :  img src = Turn_On_Image.png

Turn OFF State

 When you click on the Turn Off bulb this It will Turn On the bulb.

JavaScript Code : 
<html>                                                                                                   <body>                                                                                                    <img src = "BulbTurnOffImage.jpg" alt="Turn Off" />
               <h3>Click on the Bulb to Turn it ON</h3>   
             <script>
//This JavaScript function check the above image condition if its is bulb OFF condition than this function will Turn it On.    
                   function TurnOnOff(){       
                      var image= decument.getElementById("image");    
                      if ( image.src.match("BulbOn") )                   
                              image src = "Turm OFF image.jpg"          
                     else                                                       
                              image src = "Turn ON image.jpg"            
                        }                                                                                          </script>                          
          </body>                                                                                     </html>

 Output :
Turn ON State
Now your JavaScript Programming bulb On, You can try it by Yourself too. 

If you have Question don't forget to ask your question in Comment Box.
, , ,

7 comments:


  1. Awesome yaar thanks for this

    ReplyDelete
  2. Hey it's work. Good

    ReplyDelete
  3. This blog provide some useFul knowledge. Thanks for sharing this knowledge

    ReplyDelete
  4. Replies
    1. I thing you should read this post carefully from starting to end you can copy this code and run it yourself.

      Delete
  5. It didn't work for me.How did u guys do it?

    ReplyDelete