Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Friday, 15 October 2010

Pretty styles!

0 comments
So we start off with a line of text yeah?


Add a bit of CSS styling and... bam!


I was originally trying to embed some webfonts with @font-face but it doesn't seem to like working within JavaScript so I've decided to go with one of my favourite classic fonts; Century Gothic. I think it looks pretty smart with some styles thrown all over it. I have used the CSS3 property 'text-shadow' though, which requires a webkit browser.

Close-up -

JavaScript Array

0 comments
In order to make my piracy myths appear randomly on the webpage I have used JavaScript to create a function. An array has been created containing all the myths then the floor() and random() methods of the Math object are used to pick one out at random. The code for this is demonstrated below -

function getMyth()
{
var piMyths = new Array();
piMyths[0] = "Pirates only want things for free.";
piMyths[1] = "Downloading music damages the artist.";
piMyths[2] = "No artists support piracy.";
piMyths[3] = "Piracy is stealing.";
piMyths[4] = "Piracy will kill creative arts.";
piMyths[5] = "Digital piracy costs the industy billions.";
piMyths[6] = "Piracy is illegal, and therefore wrong.";
piMyths[7] = "Pirates are all young people who don't really understand how society works.";
piMyths[8] = "Using pay services is so much easier.";
piMyths[9] = "It isn't expensive to just pay for stuff anyway.";
piMyths[10] = "You don't support the band by pirating their music.";
var randValue = Math.floor(Math.random() * piMyths.length);
document.write(piMyths[randValue]);
}
By using an array more information can be added quickly and easily by just editing this one piece of JavaScript. I have placed this script in an external .js document that can be linked to from any of my HTML pages. Then all I have to do is call upon the JavaScript function in the body of my HTML document in order to make the random quotes show up.

This can be see in action at http://jennoefur.comyr.com/piracy/arraydemo.html. Refreshing the page will bring up one of the randomly selected quotes.

Wednesday, 9 December 2009

Finished Website

0 comments
Finally finished my website after a couple of hours of annoying validation errors and fixes. Overall I'm very happy with it :)

JavaScript elements include text size changer, image gallery and a function to remove the background image.

Click the screenshot to take a look.


If you're picky enough to check the validation yourself it will come up with two errors but these are not actually on the website but in some code added by the free host I've used to check analytics or something.

Saturday, 24 October 2009

JavaScript

0 comments
Here are some of the JavaScript programs we've been working on.

Adding VAT to an Amount
<script language='JavaScript'>
a=parseFloat(prompt('Enter cost',0)); // ask user for amount to add vat to
cost=a; // set variable cost to the amount entered by user for a
vat=cost*17.5/100; // set variable vat to the amount of cost multiplied by 17.5 and divided by 100
document.write('£',cost,'+VAT at 17.5% =','£',cost+vat); // write sum of cost and vat to screen
</script>

Adding Numbers
<script language='JavaScript>
a=parseFloat(prompt('Number to start from?',0)); // ask user for number to start adding from
b=parseFloat(prompt('Number to stop at?',0)); // ask user for number to stop adding to
count=a; // set variable count to amount set by user in a
sum=0; // set variable sum to zero
while (count<b) { // while count is less than the amount the user entered for b do the following
count=count+1; // add one to the amount of count
sum=sum+count; // add the amount of count to the amount of sum
}
document.write(sum); // write amount of sum to screen
</script>

Creating a Slash made of d's
<script language='JavaScript'>
a=parseFloat(prompt('How many rows?',0)); // ask for user to input number of rows
row=0; // set variable row to zero
while (row<a) { // while row is less than the number inputted by the user for a do the following
space=0; // set variable space to zero
while (space<row) { // while space is less than zero do the following
document.write(" "); // write a space to the screen that the browser will not ignore
space=space+1; // add one to the amount of space
}
document.write("d<br>"); // write the letter d to the scren
space=0; // set variable space to zero
row=row+1; // add one to the amount of rows
}
</script>
 
Copyright 2010 Meow