gpt4 book ai didi

javascript - 是否可以在javascript中输入一个atoomnumber并输出一个atoomname?

转载 作者:行者123 更新时间:2023-11-28 03:07:46 26 4
gpt4 key购买 nike

这是我已经尝试过但没有成功的代码:

此代码是由一个 14 岁男孩(我)编写的,所以不用担心维护。

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AAPNE berekenen</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1 class="title" id="title">Dit zijn de resultaten:</h1>
<form id="Form">
Atoomnummer: <br>
<input id="Atoomnummer" type="text" placeholder="Type the Atoomnumber"> <br>
Massa: <br>
<input id="Massa" type="text" placeholder="Type the massa of the atoom"> <br>
</form>
<button type="button" onclick="berekenen();" >Bereken atoom</button>
<button type="button" onclick="Writing();" >Krijg antwoorden</button>
<script src="script.js"></script>
</body>
</html>

CSS:

body {
background-color: rgba(145, 248, 248, 0.562);
border: 2px solid black;
}
button {
padding: 10px;
padding-right: 10px;
margin: 20px;
}
input {
padding: 10px;
margin: 5px;
}

Javascript

var Atoomnaam;
var Atoomnummer;
var Protonen;
var Neutronen;
var Elektronen;
var TextInput;
var index;
var Naam = [
"Calcium(Ca)","Scandium(Se)","Titaan(Ti)","Vanadium(V)","Chroom(Cr)","Mangaan(Mn)","Ijzer(Fe)","Kobalt(Co)"
,"Nikkel(Ni)","Koper(Cu)","Zink(Zn)","Galium(Ga)","Germanium(Ge)","Arseen(As)","Seleen(Se)","Broom(Br)","Krypton(Kr)","Rubidium(Rb)","Strontium(Sr)","Yttrium(Y)","Zirkonium(Zr)","Niobium(Nb)"
,"Molybdeen(Mo)","Technetium(Te)","Ruthenium(Ru)","Rhodium(Rh)","Palladium(Pd)","Zilver(Ag)","Cadmiun(Cd)","Indium(In)","Tin(Sn)","Antimoon(Sb)","Telluur(Te)","Jood(I)","Xenon(Xe)"
,"Cesium(Cs)","barium(Ba)","lanthaan(La)","Cerium(Ce)","Praseodymium(Pr)","Neodymium(Nd)","Promethium(Pm)","Samarium(Sm)","Europium(Eu)","Gadolinium(Gd)","Terbium(Tb)","Dysprosium(Dy)"
,"Holium(Ho)","Erbium(Er)","Thulium(Tm)","Ytterbium(Yb)","Lutetium(Lu)","Halfnium(Hf)","Tantaal(Ta)","Wolfraam(W)","Renium(Re)","Osmiun(Os)","Iridium(Ir)","Platina(Pt)","Goud(Au)","Kwik(Hg)"
,"Thallium(Tl)","Lood(Pb)","Bismut(Bi)","Pololnium(Po)","Astaat(At)","Radon(Rn)","francium(Fr)","Radium(Ra)","Actinimiun(Ac)","Thorium(Th)","Protactinium(Pa)","Uraan(U)","Neptunium(Np)"
,"Plutonium(Pu)","Americium(Am)","Curium(Cm)","berkelium(Bk)","Californium(Cf)","Einsteinium(Es)","Fermium(Fm)","Menselevium(Md)","Nobelium(No)","Lawrencien(Lr)","Rutherfordium(Rf)"
,"Dubnium(Db)","Seaborgium(Sg)","Bohrium(Bh)","Hassium(Hs)","Meitnerium(Mt)","Darmstadtium(Ds)","Roentgenium(Rg)"];
var TempMassa;
var Massa;
var Temp1;
var Temp2;
var Temp3;
var AtoomNum;
function NaamOfAtoom (AtoomNum) {
switch (AtoomNum) {
case 0:
Atoomnaam ="Dit molecuul bestaat niet";
break;
case 1:
Atoomnaam = "Waterstof(H)"
case 2:
Atoomnaam = "Helium(He)";
break;
case 3:
Atoomnaam = "Lithium(Li)";
break;
case 4:
Atoomnaam = "Beryllium(Be)";
break;
case 5:
Atoomnaam = "Boor(B)";
break;
case 6:
Atoomnaam = "Koolstof(C)";
break;
case 7:
Atoomnaam = "Stikstof(N)";
break;
case 8:
Atoomnaam = "Zuurstof(O)";
break;
case 9:
Atoomnaam = "Fluor(F)";
break;
case 10:
Atoomnaam = "Neon(Ne)";
break;
case 11:
Atoomnaam = "Natrium(Na)";
break;
case 12:
Atoomnaam = "Magnesium(Mg)";
break;
case 13:
Atoomnaam = "Aluminium(Al)";
break;
case 14:
Atoomnaam = "Silicium(Si)";
break;
case 15:
Atoomnaam = "Fosfor(P)";
break;
case 16:
Atoomnaam = "Zwafel(S)";
break;
case 17:
Atoomnaam = "Chloor(Cl)";
break;
case 18:
Atoomnaam = "Argon(Ar)";
break;
case 19:
Atoomnaam = "Kalium(K)"
};
};

function berekenen () {
Protonen = document.getElementById("Atoomnummer").value;
AtoomNum = document.getElementById("Atoomnummer").value;
Elektronen = document.getElementById("Atoomnummer").value;
Massa = document.getElementById("Massa").value;
Neutronen = Massa - Protonen;
}
function Writing() {
console.log(Atoomnaam, AtoomNum, Atoomnummer);
alert("Protoon(en) = " + Protonen + "," + " Neutroon(en) = " + Neutronen + "," + " Elektron(en) = " + Elektronen + "," + " Naam = " + Atoomnaam)
}

免责声明:Javascript 尚未完成,但它不起作用,我希望它首先起作用,然后我可以完成其余的原子,如果您无法准备好它,请不要担心,它是用荷兰语编写的。

最佳答案

我用一个可行的解决方案制作了一个 plunker: https://plnkr.co/edit/QyAglTqoVx8k5RhZbenV?p=preview

是的,它需要将 NaamOfAtoom(AtoomNum) 放入 berekenen() 函数中以填充该 Atoomnaam 变量,并更改开关。

基本上,当您进行切换时,case是数字,但AtoomNum是一个字符串(您也可以输入字母) ,所以它没有输入任何案例选项。因此相当于 12 === '12' 返回 false。 switch 是严格比较 === 而不是仅比较 ==

添加parseInt(number)解决了switch部分。

关于javascript - 是否可以在javascript中输入一个atoomnumber并输出一个atoomname?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60455202/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com