Practical 5 (BSBC-205)
<!--
Write a JavaScript code to print your name with each letter in different size and color.
-->
<!DOCTYPE html>
<html>
<head>
<title>Fourth JavaScript</title>
<style>
p {
text-align: center;
}
</style>
</head>
<body id="body">
<p id="hello"></p>
<script>
function rand() {
var hello = document.getElementById("hello");
hello.innerHTML = "";
var name = "Ajay Bhatia";
for (var i = 0; i < name.length; i++) {
var tag = '<span id="s' + (i+1) + '">' + name.charAt(i) + '</span>';
hello.innerHTML += tag;
var span = document.getElementById("s" + (i+1));
var size = Math.ceil(Math.random() * 12);
span.style.fontSize = size + "em";
var r = Math.ceil(Math.random() * 255);
var g = Math.ceil(Math.random() * 255);
var b = Math.ceil(Math.random() * 255);
span.style.color = "rgb(" + r + ", " + g + ", " + b + ")";
var r = Math.ceil(Math.random() * 255);
var g = Math.ceil(Math.random() * 255);
var b = Math.ceil(Math.random() * 255);
document.getElementById("body").style.background = "rgb(" + r + ", " + g + ", " + b + ")";
}
}
(function() {
window.setInterval(rand, 1000);
})();
</script>
</body>
</html>
Write a JavaScript code to print your name with each letter in different size and color.
-->
<!DOCTYPE html>
<html>
<head>
<title>Fourth JavaScript</title>
<style>
p {
text-align: center;
}
</style>
</head>
<body id="body">
<p id="hello"></p>
<script>
function rand() {
var hello = document.getElementById("hello");
hello.innerHTML = "";
var name = "Ajay Bhatia";
for (var i = 0; i < name.length; i++) {
var tag = '<span id="s' + (i+1) + '">' + name.charAt(i) + '</span>';
hello.innerHTML += tag;
var span = document.getElementById("s" + (i+1));
var size = Math.ceil(Math.random() * 12);
span.style.fontSize = size + "em";
var r = Math.ceil(Math.random() * 255);
var g = Math.ceil(Math.random() * 255);
var b = Math.ceil(Math.random() * 255);
span.style.color = "rgb(" + r + ", " + g + ", " + b + ")";
var r = Math.ceil(Math.random() * 255);
var g = Math.ceil(Math.random() * 255);
var b = Math.ceil(Math.random() * 255);
document.getElementById("body").style.background = "rgb(" + r + ", " + g + ", " + b + ")";
}
}
(function() {
window.setInterval(rand, 1000);
})();
</script>
</body>
</html>
Comments
Post a Comment
Post Your Valuable Comments