In other words, your original code should look something like this:
Code:
<script type="text/javascript">
function convertRating(rating) {
var pic = "<img src=\"star.gif\" height=\"20\"\/>";
if (rating == 1) {
document.write(pic);
}
else if (rating == 2) {
document.write(pic + pic);
}
else if (rating == 3) {
document.write(pic + pic + pic);
}
else if (rating == 4) {
document.write(pic + pic + pic + pic);
}
else if (rating == 5) {
document.write(pic + pic + pic + pic + pic);
}
}
</script>
However, using a "for" statement can simplify things a bit since you're essentially doing the same thing over and over:
Code:
<script type="text/javascript">
function convertRating(rating) {
for(i = rating; i > 0; i--) {
document.write("<img style=\"height: 20px; width: 20px;\"");
document.write(" title=\"" + rating + " Stars\"");
document.write(" alt=\"" + rating + " Stars\"");
document.write(" src=\"star.gif\"\/>");
}
}
</script>