用反向字母输出编写提示

时间:2015-11-18 18:33:21

标签: javascript typescript reverse prompt letters

enter image description here

所以这里我的3个错误。第一个错误,刚开始时,我没有命名前两个变量。

我需要为大学编写代码。

我们需要设置一个提示框,你可以在条目栏中写一个句子,按下“ok”后,它会以反向字母的形式给你一个句子。我们用TypeScript编程。我认为JavaScript很相似。

我们需要使用函数,字符串和警报。

我尝试了以下一个,但是eclipse给了我错误,我不知道如何管理,它可以使用reverseLetters的变量句子。请帮帮我,我明天需要这个。

var input: string = prompt("Place a sentence here");
var letters: string = reverseLetters (input);
alert(words + "\n" + sentence + "\n" + letters);

function reverseLetters(input){
var words = input.split(" ");
var output = new Array();
words.forEach(function(word) {
    output.push(word.split("").reverse().join(""));
});
return output.join(" ");
}
(document).ready(function () {
var sentence = "Variable Sentence";
console.log("Original Sentence: " + sentence);
var revSentence = reverseLetters(sentence);
console.log("Reverse Sentence: " + revSentence);
});

2 个答案:

答案 0 :(得分:0)

我可以帮助你解决当前的课程,但这是你的作业:

// The variable was not defined.
var words = "TODO"; // the type is inferred by TypeScript, you don't need to write: var words: string = "TODO";
var input: string = prompt("Place a sentence here");
var letters: string = reverseLetters(input);
alert(words + "\n" + input + "\n" + letters);

// Function with a one string parameter that returns a string.
function reverseLetters(input:string):string {
    var words = input.split(" ");
    var output = new Array();
    words.forEach(function(word:string) {
        output.push(word.split("").reverse().join(""));
    });
    return output.join(" ");
}

// "Programmers can use ambient declarations to tell the TypeScript compiler that some other component will supply a variable."
// https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#11-ambient-declarations
// But it's better to use `tsd` and special comment `///<reference path="path/to/jquery.d.ts">`
declare var $;

$(document).ready(function () {
    var sentence = "Variable Sentence";
    console.log("Original Sentence: " + sentence);
    var revSentence = reverseLetters(sentence);
    console.log("Reverse Sentence: " + revSentence);
});

答案 1 :(得分:0)

你错过了一些变数。在警报之前添加以下内容,它应该没问题。

cd build/64bits
phpize
export CFLAGS="-O2 -g"
./configure 
make
sudo make install