Reputation: 198
Here is my current javascript. I know that it worked until I added the 'for loop'. The point of the for loop is to switch letters. As it stands, its checking to see if groups of 3 are equal to one letter. I will fix that later, but I know there must be a syntax error, as the buttons don't fade as my mouse moves over them. I know this is a stupid question and I'll kick myself when I see the error, but I'm tired and can't find it for my life right now. Also, is this for loop a valid way of changing letters? Is that the correct way to set an array value to the new letter?
Here is the script.js:
$(document).ready(function() {
$('#button_translate').mouseenter(function() {
$('#button_translate').fadeTo('fast', 1);
});
$('#button_translate').mouseleave(function() {
$('#button_translate').fadeTo('fast', 0.7);
});
$('#button_clear').mouseenter(function() {
$('#button_clear').fadeTo('fast', 1);
});
$('#button_clear').mouseleave(function() {
$('#button_clear').fadeTo('fast', 0.7);
});
$('#button_translate').click(function() {
var dna = $('input[name=dna]').val();
var dna = dna.toUpperCase();
function allBases(text) {
var bases = /^[ACGT]+$/;
if(text.match(bases)) {
var arr = text.match(/.{1,1}/g);
/*document.write(arr + " is a DNA sequence.");*/
for (var i = 0; i < (dna.length); i++) {
if (arr[i]==='A') {
arr[i]='U'
}else if (arr[i]==='C') {
arr[i]='G'
}else if (arr[i]==='G') {
arr[i]='C'
}else if (arr[i]==='T') {
arr[i]='U'
}else{
document.write(dna + " is not a real DNA sequence. Error Code 2");
}
}
document.write(dna + " is the translated mRNA strand!");
}else{
document.write(dna + " is not a real DNA sequence.");
}
}
allBases(dna);
});
});
Upvotes: 0
Views: 816
Reputation: 156
for (var i=0; i>=((dna.length) / 3); i++) {
you probably want the loop condition to be i less than dna.length
for (var i = 0; i < (dna.length/3); i++) {
Upvotes: 2
Reputation: 388406
you have an unclosed (
in the for loop
for (var i=0; i>=(dna.length) / 3); i++) { // extra ( in i>=((dna.length) / 3)
Upvotes: 0