This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Javascript Code: A textarea with it's background color changed via JavaScript | |
$("#message").ready(function(){ | |
$("#message").css("background-color", "pink"); | |
}); | |
Javascript Code: User input appears in the DOM on Submit | |
$("button").on("click", function(){ | |
console.log( "clicked" ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#message").on("keyup", function() { | |
console.log("keyup happened"); // This console log ensures the .on() method event listener is in effect | |
var charCount = $("#message").val().length; // Method chaining occurs to return the # of characters in a DOM element; variable contains multiple data types/methods | |
console.log(charCount); // This console log ensures the variable for character count is in effect and the # of characters are printed in the console | |
$("#char-count").html(charCount); | |
if(charCount > 50) { // Conditional statements start here to change color of text based on character count value | |
$("#char-count").css("color", "red"); | |
} else { | |
$("#char-count").css("color", "black"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Javascript: For-loop in jQuery to change CSS properties in the DOM | |
$(function() { | |
var rows = $(".my-row"); | |
console.log("row function"); | |
for(var i=0; i<rows.length; ++i) { | |
if (i%2===0) { | |
$(rows[i]).css("background-color", "grey"); | |
}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Javascript: 4 boxes of photos with hover-on/out jQuery effect | |
var myKitties = [ { title: "1st", pic: "https://www.petfinder.com/wp-content/uploads/2012/09/Blog-Kitty-Cam-solo.jpg" }, { title: "2nd", pic: "http://www.animal-photography.com/thumbs/red_tabby_long_hair_kitten_~AP-0UJFTC-TH.jpg" }, | |
{ title: "3rd", pic: "http://www.animal-photography.com/thumbs/silver_tabby_kittens~AP-0JO6Y9-TH.jpg" }, | |
{ title: "4th", pic: "http://www.animal-photography.com/thumbs/silver_tabby_kitten_looking_up~AP-0DLVMB-TH.jpg" } | |
]; | |
$( document ).ready( function(){ | |
for(var i=0; i<myKitties.length; ++i) { | |
$("#" + i ).css("background-image", "url(" + myKitties[i].pic + ")" ); //Dot notation occurs here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HTML Google Maps: | |
<div class="gmaps"> | |
<iframe | |
width="275" | |
height="150" | |
frameborder="0" style="border:0" | |
src="https://www.google.com/maps/embed/v1/place?key=AIzaSyDjenMNMxYamTc3d9Ol6jOOUa7FlldHIng&q=Space+Needle,Seattle+WA"> | |
</iframe> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def greeting | |
puts "Please enter your name:" | |
name = gets.chomp | |
puts "Hello " + "" + name | |
end | |
greeting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (5+5==10) | |
puts "this is true" | |
else | |
puts "this is false" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fav_foods | |
food_array = [] | |
3.times do | |
puts "Name a favorite food." | |
food_array << gets.chomp | |
end | |
puts "Your favorite foods are #{food_array.join(", ")}." | |
food_array.each do |food| | |
puts "I like #{food} too!" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Cat | |
attr_reader :color, :breed | |
attr_accessor :name | |
def initialize(color, breed) | |
@color = color | |
@breed = breed | |
@hungry = true | |
end | |
def feed(food) | |
puts "Mmmm, " + food + "!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Pet | |
attr_reader :color, :breed | |
attr_accessor :name | |
def initialize(color, breed) | |
@color = color | |
@breed = breed | |
@hungry = true | |
end | |
def feed(food) | |
puts "Mmmm, " + food + "!" |
OlderNewer