如何制作一个字符串变量,这是通过它的数字进行的?例如,大写A为65。ASCII图表

发布于 2025-01-24 07:18:14 字数 883 浏览 2 评论 0原文

我想拥有它,以便提示用户输入第二个字符串,该字符串将比第一个字符串以比第一个字符串较低。我不明白如何使字符串成为一个数字?我什至需要这样做吗?

function SortStringAlphabetically() {
  // Declare variables
  var stringOne = "";
  var stringTwo = "";
  var output;
  

  // Get input from user
  stringOne = prompt("Please enter a string");
  stringTwo = prompt("Please enter enter a string that will sort lower alphabetically than the first string.");

  // Convert input strings to numbers
  stringOne = Number(stringOne);
  stringTwo = Number(stringTwo);

  if ( stringTwo > stringOne) {
    output = "very good" + stringOne + "sorts lower than" + stringTwo + ".";
  } else {
    output = stringOne + "sorts higher than" + stringTwo + "try again";
  }

  document.write(output);
}

// Run the program
SortStringAlphabetically();
// END OF YOUR CODE

I want to have it so the user is prompted to enter the second string, that will sort lower alphabetically than the first string. I don't understand how to make a string a number? Do I even need to do that?

function SortStringAlphabetically() {
  // Declare variables
  var stringOne = "";
  var stringTwo = "";
  var output;
  

  // Get input from user
  stringOne = prompt("Please enter a string");
  stringTwo = prompt("Please enter enter a string that will sort lower alphabetically than the first string.");

  // Convert input strings to numbers
  stringOne = Number(stringOne);
  stringTwo = Number(stringTwo);

  if ( stringTwo > stringOne) {
    output = "very good" + stringOne + "sorts lower than" + stringTwo + ".";
  } else {
    output = stringOne + "sorts higher than" + stringTwo + "try again";
  }

  document.write(output);
}

// Run the program
SortStringAlphabetically();
// END OF YOUR CODE

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文