-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrna transcription.html
66 lines (48 loc) · 1.46 KB
/
rna transcription.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html>
<body>
<h1>RNA TRANSCRIPTION</h1>
<button type="button" onclick="myFunction()">Try it</button>
<script>
/*The problem description:
Write a program that, given a DNA strand, returns its RNA complement (per RNA transcription).
Both DNA and RNA strands are a sequence of nucleotides.
The four nucleotides found in DNA are adenine (A), cytosine (C), guanine (G) and thymine (T).
The four nucleotides found in RNA are adenine (A), cytosine (C), guanine (G) and uracil (U).
Given a DNA strand, its transcribed RNA strand is formed by replacing each nucleotide with its complement:
G -> C
C -> G
T -> A
A -> U
*/
function myFunction(){
var dna = prompt("ENTER THE DNA CHAIN PLEASE");
i=0;
while (i<dna.length) {
if (dna.charAt(i) != "G" && dna.charAt(i) != "T" && dna.charAt(i) !="A"&& dna.charAt(i) !="C") {
dna = prompt("DNA CHAIN SHOULD CONTAIN ONLY G,C,T,A ELEMENTS. PLEASE TRY AGAIN");
i = 0;
}
else {
i++;
}
}
var rna = dna.replace(/G|C|T|A/gi, function Replace(x){
if (x === "G") {
return "C";
}
else if(x === "C"){
return "G";
}
else if(x === "T"){
return "A";
}
else if (x === "A") {
return "U";
}
})
alert(rna);
}
</script>
</body>
</html>