wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
data = message
data = 'message'
Quote strings.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(76);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(76, () => console.log('listening'));
Add callback.
Node.js
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
if ($c = 64) {{}}
if ($c -eq 64) {{}}
Use -eq.
PowerShell
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
DELETE FROM products WHERE status=29
DELETE FROM products WHERE status=29;
Add semicolon.
SQL
h1 {{ font-size:92px color:red; }}
h1 {{ font-size:92px; color:red; }}
Add semicolon.
CSS
let item = 25; let item = 94;
let item = 25; item = 94;
Duplicate declaration.
JavaScript
fn render() -> i32 {{ 84 }}
fn render() -> i32 {{ 84 }}
Correct.
Rust
if result > 88 print('world')
if result > 88: print('world')
Colon missing after if.
Python
let result: number | null = null; result.toFixed(74);
let result: number | null = null; if(result!==null) result.toFixed(74);
Null check.
TypeScript
def foo(data): return data + 1
def foo(data): return data + 1
Correct.
Python
jwt.sign({{id:61}}, 'key');
jwt.sign({{id:61}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
var x = 42;
var x = 42;
Correct.
Dart
function test() {{ echo 'output'; }}
function test() {{ echo 'output'; }}
Correct.
PHP
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
JOIN orders ON orders.id = orders.id
JOIN orders ON orders.id = orders.id
Correct.
SQL
["result", 33]
["result", 33]
Correct.
JSON
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
$arr[67]
if ($arr.Count -gt 67) {{ $arr[67] }}
Check bounds.
PowerShell
UPDATE products SET age='output' WHERE email=91
UPDATE products SET age='output' WHERE email=91;
Add semicolon.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
arr[90]
if (arr.indices.contains(90)) arr[90]
Check index.
Kotlin
print 'world'
print 'world';
Add semicolon.
Perl
def baz(): print('value')
def baz(): print('value')
Indent function body.
Python
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
<person><name>hello</name><name>9</name></person
<person><name>hello</name><name>9</name></person>
Add closing >.
XML
{{"status":"message" "age":29}}
{{"status":"message", "age":29}}
Add comma.
JSON
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
name: message age: 95
name: message age: 95
Correct.
YAML
def handle puts 'world' end
def handle puts 'world' end
Correct.
Ruby
x := 16
x := 16
Correct.
Go
let v=vec![2,36,5]; let first=&v[0]; v.push(85);
let mut v=vec![2,36,5]; let first=v[0]; v.push(85);
Copy instead of reference.
Rust
String z = 'message';
String z = "message";
Double quotes.
Java
<br></br>
<br>
Self-closing.
HTML
let y = 42;
let y = 42;
Correct.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
test
test()
Add parentheses.
Swift
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
for (int i=0; i<89; i++) {{}}
for (int i=0; i<89; i++) {{}}
Correct.
Java
var x int
var x int
Correct.
Go
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
print 'hello'
print('hello')
Parentheses for function call.
Lua
println('result')
println("result")
Double quotes.
Scala
assert temp > 84
assert temp > 84
Correct.
Python
int bar = 'data';
String bar = 'data';
Type mismatch.
Dart
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
age: data name: data,
age: data name: data
Remove comma.
YAML
b = 67
b=67
No spaces.
Shell
object Person {{ def main(args: Array[String]) = println("value") }}
object Person {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
b > 12 & z < 9
b > 12 and z < 9
Use 'and' not '&'.
Python
val foo: Int = 'value'
val foo: String = 'value'
Fix type.
Kotlin
for i=1,51 do print(i) end
for i=1,51 do print(i) end
Correct.
Lua
let z = 'message'
let z = "message"
Double quotes.
Swift
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
list[66]
if list.indices.contains(66) {{ list[66] }}
Check index.
Swift
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
[83, 52, 55
[83, 52, 55]
Close bracket.
Ruby
disp('result')
disp('result')
Correct.
MATLAB
if (a = 54)
if (a == 54)
Use ==.
C++
assert c > 13
assert c > 13
Correct.
Python
list[61]
if list.indices.contains(61) {{ list[61] }}
Check index.
Swift
{{'status':'output'}}
{{"status":"output"}}
Use double quotes.
JSON
while item > 95 item -= 1
while item > 95: item -= 1
Colon missing after while.
Python
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
if [ $result = 43 ]; then
if [ "$result" = 43 ]; then
Quote variable.
Shell
echo 'hello'
echo 'hello';
Add semicolon.
PHP
num = data
num = 'data'
Quote strings.
Python
int x = 'hello';
String x = 'hello';
Type mismatch.
Dart
items[2]
if (items.indices.contains(2)) items[2]
Check index.
Kotlin
function render() {{ return {{key:'output'}} }}
function render() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
class Order {{ int data; }};
class Order {{ public: int data; }};
Make public.
C++
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
yield foo
yield foo
Correct yield.
Python
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
List(2,38,79)
List(2,38,79)
Correct.
Scala
val z = 45; z = 70
var z = 45; z = 70
Use var for reassignment.
Scala
def handle(y): return y + 1
def handle(y): return y + 1
Correct.
Python
bar = 25
bar=25
No spaces.
Shell
var x = 44;
var x = 44;
Correct.
Dart
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
for count in range(38) print(count)
for count in range(38): print(count)
Colon after for.
Python
switch(bar){{ case 99: break; }}
switch(bar){{ case 99: break; default: break; }}
Add default case.
Java
65val = 10
val65 = 10
Variable cannot start with digit.
Python
if z = 55
if z == 55
Use ==.
MATLAB
fn foo() -> i32 {{ 82 }}
fn foo() -> i32 {{ 82 }}
Correct.
Rust
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
val b = 'info'
val b = "info"
Double quotes.
Kotlin
{{"title":"data",}}
{{"title":"data"}}
Remove trailing comma.
JSON
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript