• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • Home
  • Learn to Code
    • Python
    • JavaScript
  • Code Snippets
    • HTML
    • JavaScript
    • jQuery
    • PHP
    • Python
    • SAS
    • Ruby
  • About

The Programming Expert

The Programming Expert

Code Snippets to Help You Solve Your Programming Headaches Fast

Find Solutions for Your Programs in Python, PHP, HTML, SAS, JavaScript and more.

Become an Expert Programmer through Interactive Examples

JavaScript
jQuery
Python
PHP
HTML
SAS
VBA

JavaScript – Featured Example
How to Rotate an Image using JavaScript

Rotate image

<div id="div1">
  <img id="image1" src="https://theprogrammingexpert.com/wp-content/uploads/example-img1.png">
  <div id="click-me" onclick="rotateImage()">Rotate image</div>
</div>

<script>

var rotateDegrees = 0;  
function rotateImage(){
  rotateDegrees += 30;
  document.getElementById("image1").style.transform = "rotate(" + rotateDegrees + "deg)";
};

</script>
See More JavaScript Examples
jQuery – Featured Example
Example of Using the jQuery clone() Method

Clone box


<style>.box{ float: left; width: 50px; height: 50px; background: #7bbfa2; margin-right: 10px; margin-bottom: 10px; }</style>
<div id="div2">
  <div class="box"></div>
</div><div class="clear"></div>
<div id="click-me2" class="click-me">Clone box</div>

<script>
$("#click-me2").click(function(){
  var clonedP = $(".box:first").clone();
  var randomColor = "#" + (Math.floor(Math.random()*16777215).toString(16));
  clonedP.css("background",randomColor)
  clonedP.appendTo("#div2");
});
</script>
See More jQuery Examples
Python – Featured Example
Reverse String with Recursion in Python
string = "Hello"

def reverse_string(string):
    if len(string) == 1:
        return string
    return reverse_string(string[1:]) + string[0:1]

print(reverse_string(string))

#Output:
olleH
See More Python Examples
PHP – Featured Example
How to Check If String Contains Substring in PHP
$string = "I love to program!";
$substring = "program";

$result = str_contains($string,$substring)   /* $result = true */
See More PHP Examples
HTML – Featured Example
HTML Scrollable Div with Dynamic Content
This is a scrollable div

Keep clicking the button below to add enough divs to show the scrollbar.

Add text


<style>#div5 { height: 100px; width:300px; overflow-y: auto; border: 1px solid #444; padding: 5px; }</style>
<div id="div5">
  <div id="div6">This is a scrollable div</div>
</div>
<p>Keep clicking the button below to add enough divs to show the scrollbar.</p>
<div id="click-me">Add text</div>

<script>

$("#click-me").click(function(){
  $('<div class="new-div">This is a scrollable div</div>').appendTo("#div5");
});

</script>

See More HTML Examples
SAS – Featured Example
Generating Random Integers in a Range Using SAS
data k;
    a = 0;
    b = 10;
    do i = 1 to 10;
        rand_int = rand("integer",0,10);
        output;
    end;
run;
See More SAS Examples
VBA – Featured Example
VBA e – Using Exp() Function to Get Euler’s Constant e
Debug.Print Exp(1); 

'Output:
2.718281828459045
See More VBA Examples

Learn How to Program in Multiple Languages

Check out our recent programming articles below.

Python

  • How to Shutdown Computer with Python
  • Python not in – Check if Value is Not Included in Object
  • pandas nsmallest – Find Smallest Values in Series or Dataframe
  • How to Group By Columns and Find Sum in pandas DataFrame
  • Are Tuples Mutable in Python? No, Tuples are not Mutable

JavaScript

  • Remove Commas From a String in JavaScript
  • How to Clear a Textarea Field In JavaScript
  • How to Remove All Numbers From String in JavaScript
  • cleartimeout JavaScript – How the clearTimeout() Method in JavaScript Works
  • JavaScript acos – Find Arccosine and Inverse Cosine of Number

jQuery

  • Resizing an Image Using jQuery
  • Using jQuery to Move Element Before Another
  • Using jQuery to Select Multiple Classes
  • Using jQuery to Show a Div
  • Using jQuery to Get the Top Position of Element

PHP

  • php Random Number Generator with rand Function
  • Get First Element of Array in php
  • What is the Difference Between unset() and unlink() in php?
  • Using php to Copy Files Easily from One Directory to Another
  • php atan – Find Arctangent and Inverse Tangent of Number

HTML

  • What is the Correct HTML for Making a Drop-Down List?
  • How Do You Select All p Elements Inside a Div Element?
  • What Type of HTML List will Automatically Place a Number in Front of the Items?
  • How to Give a Textarea a Max Length
  • What is the Correct HTML for Making a Text Input Field?

SAS

  • SAS Uppercase – Make String Letters Uppercase with SAS upcase function
  • SAS Comments – Commenting Your SAS Code the Right Way
  • SAS where in – Subset Data by Multiple Values in Data Step
  • SAS ceil – Round Up to Ceiling of Number in a SAS Data Step
  • Change Length of Character Variable in SAS Dataset

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy